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.
Modules working ?
-
Hey, so again I feel a bit dumb asking a so-basic question, but I wasn't able to have basic modules working:
File 'a.py':
aa = 'Test'
File 'b.py':
import a print(a.aa)
Running b.py throws the following error : **AttributeError : 'module' object has no attribute 'aa' **
Any clue about what is going on ?
Thanks !
-
The
import
statement caches modules, meaning that if youimport a
more than once (even across different scripts) it will only be loaded once. Because Pythonista runs only a single Python process, this means that if youimport a
, modifya.py
and thenimport a
again, the changes toa
won't be visible right away. In the interactive prompt, runimport a
, thenreload(a)
to reload the module froma.py
, and then run yourb.py
again and see if it works.If that didn't help, see if there are any other files named
a.py
that might be imported instead of the one you want. Pythonista doesn't come with any module nameda
by default, but if you have a filea.py
in your Script Library or site-packages, that might be imported wrongly. If you want to find out where the modulea
was imported from, seea.__file__
. -
It works as expected for me. Try adding
reload(a)
line just after the import line. Also, make sure the filename is all lowercase. -
Thanks guys, the reload() trick did it !