Difference between revisions of "Pyton multifile source"
From emboxit
m (1 revision) |
|
(No difference)
|
Latest revision as of 16:51, 11 September 2015
- The key is "import".
import yourmodule newinstance = yourmodule.YourClass()
or you could say:
from yourmodule import YourClass newinstance = YourClass()
Also there is the "package" solution where you have a folder "Modules" (you can call the folder whatever you want)
with several .py files which can all contain 1 or more classes.
Inside the Modules folder you put a file called:
- __init__.py (notice double _ before and after) where you import all modules within the folder.
Folder hiearachy:
Modules /Functions.py /MyOsRelatedSTuff.py /whatever.py /__init__.py
Inside __init__.py
from Functions import * import MyOsRelatedSTuff import whatever
Notice that you exclude the .py - then to import this in your main_app.py just:
Import foldername
In our case:
Import Modules
Then to use a class within Functions you need to call
Modules.Functions.YourClass()