How do I structure Python code in modules / packages?
source link: https://www.codesd.com/item/how-do-i-structure-python-code-in-modules-packages.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How do I structure Python code in modules / packages?
Assume I have this barebones structure:
project/
main.py
providers/
__init.py__
acme1.py
acme2.py
acme3.py
acme4.py
acme5.py
acme6.py
Assume that main.py
contains (partial):
if complexcondition():
print providers.acme5.get()
Where __init__.py
is empty and acme*.py
contain (partial):
def get():
value=complexcalculation()
return value
How do I change these files to work?
Note: If the answer is "import acme1", "import acme2", and so on in __init__.py
, is there a way to accomplish that without listing them all by hand?
This question asked today, Dynamic Loading of Python Modules, should have your answer.
Related Articles
How do you run Python code using Emacs?
How do I save Python code in JSON?
How to translate this Python code into Node.js
How to use raw python code in a Django model?
How to organize my Python code in several classes?
how to update mac python without reinstalling modules
how to use the python multi-processing module
How to have the python code and the markdown in a cell
How to parallelize my python code
How do I structure the code correctly in Python?
How do I protect Python code?
tensorflow: How to put my python code on Google Cloud as a service
How to create a python code for Mac OS X using cx_freeze on Windows?
How to convert this Python code to C ++
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK