https://github.com/pwwang/python-import-system
Python import system diagram
https://github.com/pwwang/python-import-system
diagram python python-imports
Last synced: 8 months ago
JSON representation
Python import system diagram
- Host: GitHub
- URL: https://github.com/pwwang/python-import-system
- Owner: pwwang
- Created: 2020-12-11T23:10:48.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-12-12T00:24:21.000Z (about 5 years ago)
- Last Synced: 2025-04-29T09:56:10.760Z (8 months ago)
- Topics: diagram, python, python-imports
- Language: Jupyter Notebook
- Homepage:
- Size: 16.6 KB
- Stars: 17
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

Diagram is drawn based on python's [office documentation][1]
## Pseudo code
```python
# import name, __import__(name), importlib.import_module(name), etc
if name in sys.modules:
if sys.modules[name] is None:
raise ModuleNotFoundError
else if "from import statement":
locals()[name] = module
else:
return module
else:
for finder in sys.meta_path:
spec = finder.find_spec(name, ...)
if spec is not None:
if spec.loader is None:
raise ImportError
else:
module = spec.loader.create_module(spec)
spec.loader.exec_module(module)
if "from import statement":
locals()[name] = module
else:
return module
else:
continue
else:
raise ModuleNotFoundError
```
## Experiments
See [playground.ipynb](./playground.ipynb) for some experiments on the diagram.
[1]: https://docs.python.org/3/reference/import.html