Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pwwang/python-import-system
Python import system diagram
https://github.com/pwwang/python-import-system
diagram python python-imports
Last synced: 17 days 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 (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2020-12-12T00:24:21.000Z (almost 4 years ago)
- Last Synced: 2024-10-20T11:17:54.065Z (18 days ago)
- Topics: diagram, python, python-imports
- Language: Jupyter Notebook
- Homepage:
- Size: 16.6 KB
- Stars: 17
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![Python Import System](./Python_Import_System.svg)
Diagram is drawn based on python's [office documentation][1]
## Pseudo code
```python
# import name, __import__(name), importlib.import_module(name), etcif 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