The import include file feature of Python is similar to PHP's include, but more specifically, it should be more like PHP require, because the import of Python as long as the target does not exist in the error program can not be executed down. To include the files in the directory, PHP only need to give the path to OK. Python is different, let's take a look at the example below.
Directory structure:
a.py to import the b.py file under the dir directory. The a.py code is as follows:
Copy the Code code as follows:
# Coding=utf-8
"b.py file under import dir directory"
Import Dir.b
Print Dir.b.name
Execute a.py Error
Tip The name of this module cannot be found dir.b. By finding the official documentation, you will need to declare a __init__.py file in the directory when you want to include the files in the directory, even if the file is empty. Of course, this file can also start some data.
Then, under Dir, create a new __init__.py file with the following directory structure:
Re-execute a.py, everything ok!
Transferred from: http://www.jb51.net/article/54323.htm
Method of the Py file under the Python Reference (import) folder