Python Study Notes: Common Modules

Python Common Libraries (Official website: http://docs.python.org/release/2.5.2/lib/lib.html)

  • import os // Functions related to the operating system: directories, files, system command execution (system), fork, exec family, etc.
  • import sys // System-specific parameters and common processing functions
  • import subprocess // Replaces older os execution functions (like pipes)
  • import multiprocessing // Inter-process communication: processes, message queues, shared memory
  • import threading // Inter-thread communication: threads, thread queues, thread locks
  • import thread // Another library/method for inter-thread creation and communication
  • import Queue // Message queues
  • import time // Time operations and functions
  • import signal // Signal handling functions (e.g., signal)
  • import socket // Socket communication functions: socket, accept, gethostname, connect, listen, etc.
  • import urllib
  • import praselib
  • import smtplib
  • import xmllib
  • import telnetlib
  • ...

Python Compilation File Formats

  • .pyc
    Python compiled binary cross-platform files. Note that lower versions cannot load .pyc files generated by higher versions.

    • Usage in code:
      1
      2
      import py_compile
      py_compile.compile("dirpath")
    • Command line:
      1
      python -m py_compile *.py
    • Note: There is also a compileall library available.
  • .pyo
    Python optimized compiled binary cross-platform files. Similarly, lower versions cannot load files generated by higher versions.

    • Command line:
      1
      python -O -m py_compile *.py
  • .pyd
    Python dynamic link libraries (DLLs).


Sources & References