May 10th Thursday (五月 十日 木曜日)

来源:互联网 发布:淘宝全球买手招募 编辑:程序博客网 时间:2024/04/28 10:28

  Each module has its own private symbol table, which is used as the global symbol table by
all functions defined in the module. Thus, the author of a module can use global variables
in the module without worrying about accidental clashes with a user's global variables.  On
the other hand, if you know what you are doing you can touch a module's global variables with
the same notation used to refer to its functions, modname.itemname.

  Modules can import other modules. It is customary but not required to place all import
statements at the beginning of a module (or script, for that matter). The imported module names
are placed in the importing module's global symbol table.

  When a module named spam is imported, the interpreter searches for a file named spam.py in
the current directory, and then in the list of directories specified by the environment variable
PYTHONPATH. This has the same syntax as the shell variable PATH, that is, a list of directory names.
When PYTHONPATH is not set, or when the file is not found there, the search continues in an installation
-dependent default path; on Unix, this is usually .:/usr/local/lib/python.

  Actually, modules are searched in the list of directories given by the variable sys.path which is
initialized from the directory containing the input script (or the current directory), PYTHONPATH and
the installation-dependent default.  

原创粉丝点击