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.
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.
os模块提供了一种跨平台的方式来使用操作系统特定的功能。os.stat()函数返回关于指定路径的统计信息,帮助判断文件是否损坏。虽然这个功能在大多数操作系统上可用,但过度依赖特定系统的扩展可能会影响程序的移植性。在遇到如无效或不可访问的文件名和路径等问题时,os模块的函数会抛出OSError。
241

被折叠的 条评论
为什么被折叠?



