python文档自译:os模块-01【说明部分】

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)