The import of Python contains file features similar to those in PHP, but more specifically, it should be more like the require in PHP, because the error program cannot be executed as long as the target does not exist in Python. 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 this example.
Directory structure:
a.py to import the b.py file in the dir directory. The a.py code is as follows:
Copy Code code as follows:
# Coding=utf-8
"B.py files under the Import dir directory"
Import Dir.b
Print Dir.b.name
Perform a.py error
The hint could not find the name of this module DIR.B. By looking for an official document, you'll need to declare a __init__.py file in the directory, even if the file is empty, to include the file under the directory. Of course, this file can also be a bit of initial data.
So under Dir, create a new __init__.py file with the following directory structure:
Re-execute a.py, everything ok!