Python Standard Library笔记

1. 内建函数和异常

  1. __builtin__ 包含Python 中使用的内建函数
  2. exceptions 模块提供了标准异常的层次结构

Python 在启动时导入这两个模块, 使任何程序都能够使用它们

  1. type descriptor (类型描述符)
  2. 字典是无序的, 而列表和元组是有序的
  3. 所有的类都属于一个特殊的类类型(special class type)
  4. 所有的类实例属于一个特殊的实例类型(special instance type)
  5. 不能使用type 函数来测试一个实例是否属于一个给定的类, 所有的实例都是同样的类型

python中的异常体系

../_images/Exception.png

Exception
    SystemExit(Exception)
    StandardError(Exception)
        KeyboardInterrupt(StandardError)
        ImportError(StandardError)
        NameError(StandardError)
            UnboundLocalError(NameError)
        AttributeError(StandardError)
        SyntaxError(StandardError)
            IndentationError(SyntaxError)
                TabError(IndentationError)
        TypeError(StandardError)
        AssertionError(StandardError)
        LookupError(StandardError)
            IndexError(LookupError)
                KeyError(LookupError)
        ArithmeticError(StandardError)
            OverflowError(ArithmeticError)
            ZeroDivisionError(ArithmeticError)
            FloatingPointError(ArithmeticError)
        ValueError(StandardError)
            UnicodeError(ValueError)
        RuntimeError(StandardError)
            NotImplementedError(RuntimeError)
        SystemError(StandardError)
        MemoryError(StandardError)
EnvironmentError
    IOError(EnvironmentError)
    OSError(EnvironmentError)
        WindowsError(OSError)

2. 操作系统接口模块

  1. os 模块 提供文件和进程处理功能的
  2. os.path 模块 提供平台独立的文件名处理(分拆目录名, 文件名, 后缀等)
  3. time/datetime 模块 时间日期处理相关的

3. 类型支持模块

  1. string 模块 实现了常用的字符串处理
  2. math 模块 提供了数学计算操作和常量(pi, e都属于这类常量)
  3. cmath 模块 为复数提供了和math 一样的功能

4. 正则表达式

re 模块 正则表达式用于匹配字符串

5. 语言支持模块

  1. sys 模块可以让你访问解释器相关参数,比如模块搜索路径,解释器版本号等.
  2. operator 模块提供了和内建操作符作用相同的函数.
  3. copy 模块允许你复制对象,
  4. gc 模块提供了对垃圾收集的相关控制功能.