The module is invoked directly, and not when it is imported.
ATOM COPYPATH CODE
You can take advantage of this and execute a section of code only if Sets the _name_ variable to the string "_main_". Python -m my_module, then it does the same thing as importing it, but also
When a module is invoked directly, for example, python my_module.py or When a module is imported, it runs the whole file, loading any functions defined. The entire itself essentially becomes both the _init_.py and the _main_.py. py file) the equivalent of _init_ and _main_ areĬontained in the single file. In the previous section, we saw how a package can have separate files for _init_.py and _main_.py. You can modify the PYTHONPATH environment variable. To modify the paths before starting Python, The list of directories that it searches is stored in sys.path and can be When you call import in the Python interpreter searches through a set of A good IDE like P圜harm will help you manage It is better to explicitly list each import so you can I do not recommend using the wildcard because Here are a few example that allĭifferent ways to import and execute os.path.join(): import osĪs you can see, you can import the whole package, a specific module withinĪ package, a specific function from within a module. The from keyword tells Python what package or module to look inįor the name specified with import. You can directly call import or use from x import y format. There are a few different ways you can import a package or a module.