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模块-01【说明部分】的更多相关文章

  1. 9.9 Python 文档字符串

    9.9 Python 文档字符串. 进入 Python 标准库所在的目录. 检查每个 .py 文件看是否有__doc__ 字符串, 如果有, 对其格式进行适当的整理归类. 你的程序执行完毕后, 应该会 ...

  2. Python的路径操作(os模块与pathlib模块)

    Python的路径操作(os模块与pathlib模块) 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.os.path模块(Python 3.4版本之前推荐使用该模块) #!/u ...

  3. 第8.19节 使用__doc__访问Python文档字符串(DocStrings )

    __doc__特殊变量用于查看类.函数.模块的帮助信息,这些帮助信息存放在文档字符串中. 一. 关于文档字符串 关于文档字符串前面很多章节提到过,DocStrings 文档字符串用于程序的文档说明,并 ...

  4. 基于 Python 官方 GitHub 构建 Python 文档

    最近在学 Python,所以总是在看 Python 的官方文档, https://docs.python.org/2/ 因为祖传基因的影响,我总是喜欢把这些文档保存到本地,不过 Python 的文档实 ...

  5. python 文档

    python 文档 https://docs.python.org/2/library/index.html

  6. [译]Selenium Python文档:八、附录:FAQ常见问题

    另外一个FAQ:https://github.com/SeleniumHQ/selenium/wiki/Frequently-Asked-Questions 8.1.怎样使用ChromeDriver ...

  7. 用python把技术文档中,每个模块系列截图生成一个动态GIF

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 最近在写技术文档的时候,发现一个问题.对于每个技术步骤,都需要一个截图,这 ...

  8. [译]Selenium Python文档:目录

    作者:Baiju Muthukadan 协议:本文档采用知识共享署名 - 共享4.0国际许可. 原英文网址:http://selenium-python.readthedocs.io/index.ht ...

  9. [译]Selenium Python文档:二、初步开始

    2.1.简单使用 如果已经安装好了Selenium Python,你就可以像下面这样编写Python代码来使用它了: from selenium import webdriver from selen ...

随机推荐

  1. OracleOggan安装并测试同步数据步骤!

    Oracle Golden Gate (ogg)安装使用说明 Golden Gate(简称OGG)提供异构环境下交易数据的实时捕捉.变换.投递等功能. OGG支持的异构环境有: OGG的特性: ①对生 ...

  2. shell-字符串及整数操作符讲解与多实践

    1. 字符串测试操作符 字符串测试操作符的作用:比较两个字符串是否相同.字符串长度是否为零,字符串是否为null(注:bash区分零长度字符串和空字符串)等. "="比较两个字符串 ...

  3. git 查看本地分支和切换本地分支的命令

    查看本地分支,和当前所在的分支 git branch -vv git checkout developer 切换到developer分支

  4. 2020已经过去五分之四了,你确定还不来了解一下JS的rAF?

    不会吧,不会吧,现在都2020年了不会还真人有人不知道JS的rAF吧??? rAF 简介 rAF是requestAnimationFrame的简称: 我们先从字面意思上理解requestAnimati ...

  5. lftp源码安装时 error: Package requirements (gnutls >= 1.0.0) were not met: No package 'gnutls' found

    lftp 使用疑惑与解决方法: 一,从官网下载源码后,解压./configure后,报错: error: Package requirements (gnutls >= 1.0.0) were ...

  6. 什么是 C 和 C ++ 标准库?学编程的你应该知道这些知识!

    简要介绍编写C/C ++应用程序的领域,标准库的作用以及它是如何在各种操作系统中实现的. 我已经接触C++一段时间了,一开始就让我感到疑惑的是其内部结构:我所使用的内核函数和类从何而来? 谁发明了它们 ...

  7. 超简单的CDH6部署和体验(单机版)

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  8. laravel或者lumen门面和服务提供者使用

      关于laravel门面和服务提供者使用的一点见解,门面之词,不足之处,还请多多指教.    在laravel中,我们可能需要用到自己添加的类时,可以建立一个文件夹专门存放类文件,也可以使用lara ...

  9. 第十三章 Linux三剑客之老二—sed

    一.sed #擅长增删改查 替换 选项: -n #取消默认输出 -r #支持扩展正则使用 -i #改变文件内容 -e #允许多项编辑 内部指令: p #print 打印 d    # 删除 排除 a ...

  10. Java中的String到底占用多大的内存空间?你所了解的可能都是错误的!!

    写在前面 最近小伙伴加群时,我总是问一个问题:Java中的String类占用多大的内存空间?很多小伙伴的回答着实让我哭笑不得,有说不占空间的,有说1个字节的,有说2个字节的,有说3个字节的,有说不知道 ...