the difference between directory and Python package in Pycharm
For Python, one thing to know is that Python is a relatively lightweight, easy-to-use scripting language (which is not limited to this, and is only discussed here), and as the program grows, you may want to divide it into several files so that logic is clearer, better maintained, Or you want to use a function in several programs without having to copy and paste it into all programs.
To support this, Python has a way to place definition functions in a file and use them in scripts, which are called modules, and definitions in a module can be imported into other modules, or in the main module.
In short, the module in Python refers to a py file, if we put all the relevant code in a py file, the py file is not only the program is the module, but the program and the module is designed to be different, the purpose of the program is to run, and the purpose of the module is for other programs to reference
_ _ Init_ _.py
This file is related to the import mechanism of Python, which relates to which of your. py files are externally accessible. Sometimes, if there are many modules under a package, it is cumbersome and not elegant to import so many modules in the caller, at this point you can do this by modifying _ _ Init_ _.py.
Define the Special variable _ All_ in _ _ init_. py , and copy the module that will be included to the variable, for example , define all _=[' TIFF ' in image/_ init_ . py , ' BMP ', ' jpg '], where all corresponds to the From ... import * refers to the module, at this time in the reference party using the following statement:
In fact _ _ Init_ . Py can be empty, when it is empty, the from image import * will refer to all the modules under the image package, if you want to control the referenced module, you can define the all _
The difference between directory and Python package in Pycharm