==errno 模块==

``errno`` 模块定义了许多的符号错误码, 比如 ``ENOENT`` ("没有该目录入口") 以及 ``EPERM``
("权限被拒绝"). 它还提供了一个映射到对应平台数字错误代码的字典. [Example 2-21 #eg-2-21]
展示了如何使用 ``errno`` 模块. 在大多情况下, //IOError// 异常会提供一个二元元组, 包含对应数值错误代码和一个说明字符串.
如果你需要区分不同的错误代码, 那么最好在可能的地方使用符号名称. ====Example 2-21. 使用 errno 模块====[eg-2-21] ```
File: errno-example-1.py import errno try:
fp = open("no.such.file")
except IOError, (error, message):
if error == errno.ENOENT:
print "no such file"
elif error == errno.EPERM:
print "permission denied"
else:
print message *B*no such file*b*
``` [Example 2-22 #eg-2-22] 绕了些无用的弯子, 不过它很好地说明了如何使用
``errorcode`` 字典把数字错误码映射到符号名称( symbolic name ). ====Example 2-22. 使用 errorcode 字典====[eg-2-22] ```
File: errno-example-2.py import errno try:
fp = open("no.such.file")
except IOError, (error, message):
print error, repr(message)
print errno.errorcode[error] # 2 'No such file or directory'
# ENOENT
```

python标准库介绍——25 errno 模块详解的更多相关文章

  1. python标准库介绍——12 time 模块详解

    ==time 模块== ``time`` 模块提供了一些处理日期和一天内时间的函数. 它是建立在 C 运行时库的简单封装. 给定的日期和时间可以被表示为浮点型(从参考时间, 通常是 1970.1.1 ...

  2. python标准库介绍——27 random 模块详解

    ==random 模块== "Anyone who considers arithmetical methods of producing random digits is, of cour ...

  3. python标准库介绍——10 sys 模块详解

    ==sys 模块== ``sys`` 模块提供了许多函数和变量来处理 Python 运行时环境的不同部分. === 处理命令行参数=== 在解释器启动后, ``argv`` 列表包含了传递给脚本的所有 ...

  4. python标准库介绍——30 code 模块详解

    ==code 模块== ``code`` 模块提供了一些用于模拟标准交互解释器行为的函数. ``compile_command`` 与内建 ``compile`` 函数行为相似, 但它会通过测试来保证 ...

  5. python标准库介绍——8 operator 模块详解

    ==operator 模块== ``operator`` 模块为 Python 提供了一个 "功能性" 的标准操作符接口. 当使用 ``map`` 以及 ``filter`` 一类 ...

  6. python标准库介绍——5 re模块详解

    == re 模块== "Some people, when confronted with a problem, think 'I know, I'll use regular expres ...

  7. python标准库介绍——36 popen2 模块详解

    ==popen2 模块== ``popen2`` 模块允许你执行外部命令, 并通过流来分别访问它的 ``stdin`` 和 ``stdout`` ( 可能还有 ``stderr`` ). 在 pyth ...

  8. python标准库介绍——23 UserString 模块详解

    ==UserString 模块== (2.0 新增) ``UserString`` 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的 ...

  9. python标准库介绍——22 UserList 模块详解

    ==UserList 模块== ``UserList`` 模块包含了一个可继承的列表类 (事实上是对内建列表类型的 Python 封装). 在 [Example 2-16 #eg-2-16] 中, / ...

随机推荐

  1. 破解无线网络密码-BT3如何使用2

    本教程只作学习和交流使用,任何其它商用与本人无关, 在开始教程之前, 首先需要用到几个软件,感兴趣的朋友看完贴子后可以去百度搜一下下载地址, 虚拟机: VMware Workstation 6.5 正 ...

  2. C#中相关结构的用法及用途

    C#中Dictionary的用法及用途 http://www.cnblogs.com/linzheng/archive/2010/12/13/1904709.html C#中的Dictionary字典 ...

  3. GCD多线程使用

    - (void)showTaped { /* dispatch_get_global_queue dispatch_get_main_queue dispatch_queue_create dispa ...

  4. 分离链接散列表C语言实现实例

    /* hash_sep.h */ #ifndef _HASH_SEP_H #define _HASH_SEP_H #define MIN_TABLE_SIZE 5 struct list_node; ...

  5. eclipse使用egit插件

    本来想用myeclipse,奈何试过网上所列的常用方法,都无法成功安装egit插件.只得转到eclipse.话说eclipse不仅是免费的,启动也较myeclipse更为迅速,安装插件也非常顺利.使用 ...

  6. Mapreduce实例-分组排重(group by distinct)

    public class GroupComparator implements RawComparator<MyBinaryKey> { @Override public int comp ...

  7. 算法笔记_197:历届试题 带分数(Java)

    目录 1 问题描述 2 解决方案   1 问题描述 问题描述 100 可以表示为带分数的形式:100 = 3 + 69258 / 714. 还可以表示为:100 = 82 + 3546 / 197. ...

  8. 虚拟机里面做了个MySQLS主从:

    虚拟机里面做了个主从: 但是IO现成一直不能跟主库上的dump现成通信, Slave_IO_Running: No Last_IO_Error: error connecting to master ...

  9. Springboot UT 引入某些类

    http://www.infoq.com/cn/articles/Unit-Testing-Complete-Integration-Testing-Begins https://segmentfau ...

  10. oracle 快速备份表数据

      oracle 快速备份表数据 CreateTime--2018年2月28日17:04:50 Author:Marydon UpdateTime--2017年1月20日11:45:07 1.1.9. ...