15.1. os — Miscellaneous operating system interfaces This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see open(), if you want to manipulate paths, see the os.path module, and if you want to read all the lines in all the files on the command line see the fileinput module. For creating temporary files and directories see the tempfile module, and for high-level file and directory handling see the shutil module.
15.1. os — (各式各样的|多才多艺的)os接口
此模块提供了轻便使用OS的依赖功能。
如果只想读写file,参见open();
如果想操作paths,参见os.path 模块;
如果你想从命令行读取所有文件的所有行,参见fileinput模块;
想创建临时files和directories,参见tempfile模块;
想要更高级的,处理file和directories的功能,参见shutil模块;
Notes on the availability of these functions: The design of all built-in operating system dependent modules of Python is such that as long as the same functionality is available, it uses the same interface; for example, the function os.stat(path) returns stat information about path in the same format (which happens to have originated with the POSIX interface). Extensions peculiar to a particular operating system are also available through the os module, but using them is of course a threat to portability. An “Availability: Unix” note means that this function is commonly found on Unix systems. It does not make any claims about its existence on a specific operating system. If not separately noted, all functions that claim “Availability: Unix” are supported on Mac OS X, which builds on a Unix core. Note All functions in this module raise OSError in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.
关于这些函数的使用性说明:
1.python内置的OS依赖模块,它的设计是这样的:只要提供相同的功能,那么他们必定使用相同的接口。例如:函数os.stat(path)返回path同格式的stat信息。(恰似POSIX接口的起源。)
2.使用os模块,也可以使用特定OS的特定扩展,但从兼容性来讲,是个威胁。
3.如果有“Availability:Unix”这样的提示,意思是说,这个函数是Unix系统常见的。并不是说只在此特定的操作系统才能有。
4.如果没特殊说明,所有声张“Availability:Unix”的函数,都支持Mac OS X,它也是基于Unix内核的。
【注意】:如果file的names/paths无效,或无法访问,再或者参数类型也正确,但是无法被操作系统接收时,此模块的所有函数都会抛出OSError.
exception os.error An alias for the built-in OSError exception. os.name The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'.
异常:
os.error 内置的OSError exception的别名.
os.name 导入的操作系统依赖模块的name. 当前注册了的名字有: 'posix', 'nt', 'os2', 'ce', 'java', 'riscos'.
【译注:比如在windows7命令行print os.name,会回显:'nt'】
相关推荐
python-os模块中文帮助文档.pdf
python-os模块中文帮助文档
Python项目开发源代码-智能停车场车牌识别计费系统的程序+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7。 开发工具:...
Python项目开发源代码-RCQ读者书库程序+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:PyCharm 2018。 ...
python中os模块中文帮助文档.doc
Python项目开发源代码-Excel数据分析师程序+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.6。 可视化开发环境:PyCharm ...
图片批量处理器设计Python项目开发源代码+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:PyCharm 2018。...
Word助手程序Python项目开发源代码+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:PyCharm 2018。 ...
基于python设计开发的Word助手小程序wordhelper源码+文档说明 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:PyCharm 2018...
Python项目开发企业编码管理的程序设计源代码+开发文档说明资料: 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:Pycharm...
Python项目开发源代码-火车票分析助手的程序+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:操作系统:Windows 7、Windows 8、Windows 10。 Python版本:Python 3.7.0。 ...
PYTHONOS模块中文帮助文档.pdf
画图板程序Python项目开发源代码+开发文档说明资料 开发环境要求 本系统的软件开发及运行环境具体如下。 操作系统:Windows 7、Windows 10。 Python版本:Python 3.7.1。 开发工具:PyCharm 2018。 ...
Python的os模块封装了常见的文件和目录操作,本文只是列出部分常用的方法,更多的方法可以查看官方文档。 下面是部分常见的用法: 方法 说明 os.mkdir 创建目录 os.rmdir 删除目录 os.rename 重命名 os...
python课程设计-企业编码管理系统(源码+可执行程序exe+使用说明) 具体的操作步骤如下: (1)生成6位数字防伪编码。 (2)生成9位系列产品数字防伪编码。 (3)生成25位混合产品序列号。 (4)生成含数据分析功能...
├─千锋Python教程:第01章 第一个Python程序与数据存储及数据类型(9集) │ │ .DS_Store │ │ │ ├─code │ │ 1、数据存储.txt │ │ 2、第一个python程序.py │ │ 3、注释.py │ │ 4、输出与输入.py │ ...
PYTHONOS模块中文帮助文档[总结].pdf