Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Importing between files
-
On pythonista, how do I share information between python files. If I had a file called 'main.py' and then another called 'extension.py' and there are functions I want from extension.py in main.py, I would use 'import extension'. I do this and it calls an error that states that 'there is no module extension'
-
It is easy, put the extension.py and the main.py file in a folder with a file called
__init__.py
, them in the main.pyimport extension extension.your_function()
I hope this work for you
-
You can see this for more help
-
@sulcud Thanks so much!
-
The
__init__
is only necessary if you want to import by folder name. The key is that, if you run main.py, extension.py must be in the same folder, or otherwise on sys.path (for instance, in site-packages).