First, a summary chart:
In Pycharm, the current file directory is not typically automatically added to its own sourse_path. If you encounter other modules that cannot be in the import sibling directory,
Right-click Make_directory as-->sources root to add the current working folder to Source_path.
But the summary chart is very uncoordinated, the following to explain in detail:
(1) different modules in the same package refer to each other
After confirming that this folder path is added to SourcePath: "From Module name import class name"
(2) different packages in the same folder refer to each other
There are three ways to do this:
--You can directly refer to each other's module: "From module name import class name"
--If nothing is written in the __init__.py folder of the respective package, the two dots in front of the package name represent the files in the previous level directory
--Write your own references in the __init__.py of the package
You can then refer to the class name directly with the package name:
(3) Cross-references to different packages in different folders
It is just a matter of writing a directory, of course, if you have already referenced your class in the __init___.py file in Wx_video, it is difficult to import the class directly through the package name
Summarize:
1. When you import a package, you actually import the package's __init__.py file, so if you write another import function in init, it is equivalent to helping to import something else at the time of initialization.
2, each package directory will have a __init___.py file, this file must exist, otherwise, Python will treat this directory as a normal directory, rather than a package. It can be an __init__.py
empty file, or it can have Python code, because it __init__.py
is a module in itself.
Python file structure and import usage