Python module import

Purpose

If you create a package consisting of several modules, you need to write the folder name (package name), file name (module name), function or class name to import, and the import statement becomes long. I want to shorten these. Or, I want to import with default settings across modules.

Import specifications in Python

According to here

The imported module name is placed in the global symbol table of the importing module. The import statement has a variant that populates the name in a module directly into the symbol table of the module executing the import. (from..import ..)

So, if you import with __init__.py, you can use the imported symbols in __init__.py just by importing the package.

For example

/foo
  - __init__.py
  - bar.py

With the folder structure

$ cat bar.py
PIYO=100

$ cat __init__.py
from bar import PIYO

Then, foo.PIYO can be used with ʻimport foo`. It can be used to hide complex implementations within modules and provide libraries.

Recommended Posts

Python module import
python original module import
How Python module import works
Import python script
Python collections module
Summarize Python import
[Python] Import the module one level higher
Module import and exception handling in python
Import Error in Python3: No module named'xxxxx'
Python module (Python learning memo ④)
Create a Python module
Python from or import
Import tsv with Python
[Hikari-Python] Chapter 08-01 Module (Import Module)
python> import seiral> ImportError: No module named serial
Import cv2 ModuleNotFoundError: No module named'cv2' in python3
About Python external module import <For super beginners>
[Python] ModuleNotFoundError: No module named'urlparse'
Python
Dynamically import scripts in Python
Import vtk with brew python
About the Python module venv
Automatic update of Python module
Ruby, Python Module Installation Guide
[Python] Another way to import
Python debug and test module
Python # Snap7 Libray Import problem
[Hikari-Python] Chapter 08-02 Module (Import Package)
[Python of Hikari-] Chapter 08-03 Module (Import and use of standard library)
2015-11-26 python> Display the function list of the module> import math> dir (math)
[Python] The stumbling block of import
[Python] logging in your own module
Working with LibreOffice in Python: import
Python error: ModuleNotFoundError: No module named'flask'
python> link> from __future__ import absolute_import
python> Exit processing> import sys / sys.exit ()
Cooperation between python module and API
[Code] Module and Python version output
About Python, from and import, as
[Python] How to import the library
Use blender as a python module
Python3 socket module and socket communication flow
Python unittest module execution in vs2017
[Lambda] Make import requests available [python]
Python My Number verification module released
Try using the Python Cmd module
Python executable file conversion module comparison 2
Load Mac Python import MySQL db
Python import directory order (on anaconda)
Looking for location for mercurial python module
Master the weakref module in Python
kafka python
Python basics ⑤
python + lottery 6
Python Summary
Built-in python
Python comprehension
Studying python
Today's python error: ModuleNotFoundError: No module named
Python 2.7 Countdown
Python memorandum