call directory:


| |?? if in the program mod directly into the module, using the

 import mod from mod import *

calls or subdirectories under the module:

 SRC | |??? Lib | | |? 

the following documents from import * lib.mod2 directory structure or import lib.mod2

call of the directory:

? SRC |? |? Lib | | |? Sub import | |? Sys sys.path.append ('C:\test\ A\C') import mod import lib.mod2

in each package Python module, there is a file (this file defines the properties and methods of the package) and then It is a number of module files and subdirectories, and if there is a in the subdirectory, it is the subpackage of the package. When you import a package as a module (for example, import DOM from XML), you actually import its file. A

package is a directory with a special file The file defines the properties and methods of the package. In fact, it can be nothing to define; it can be just an empty file, but it must exist. If doesn't exist, the directory is only a directory, rather than a package, it can't be imported or contains other modules and nested packets. There is an important variable in, called __all__.

if the Directory follows

? SRC | |? Lib | |? | |? | |? Sub | |? | |?

we sometimes resorted to a trick "imported", is this:

 from lib import *

and import __all__ in turn register the package in the file in the list of sub modules and sub package into the current scope. For example:

 # file __all__ = ["mod2", "MOD3", "sub"]

: summary for the rest of the path to download the PY file, import, first to sys.path, then import.

  • package: ID cannot delete the
  • definition in package __all__, used to write Python code into
  • fuzzy

  • (not recommended for writing Python module in __init__ can be in the package created in another module to write, try to ensure that

summarized above is small to import and Python introduce the basis of the introduction, I hope to help you, if you have any questions please give me a message, Xiao Bian will reply you timely. Thank you for your support for the home website of the script!

This concludes the body part