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.
Scripts not updating on import?
-
I discovered this in a more complex set of code, but I've boiled the issue down to two very simple scripts:
from helper import helpfunc print helpfunc(6)
and
def helpfunc(val): return 2*val
All goes fine the first time I run mainprog.py and the output is 12, but if I change the "2" to a "3" in the helper.py script, then when I run the mainprog.py script, the output is still 12.
The only way I can get mainprog.py to pick up the changes in helper.py is to force quit pythonista.
Am I missing something?
-
Try
reload( helpfunc )
at the end ofmainprog.py
, it should do the math. -
Got a TypeError when I tried that. reload wanted a module.
-
Try adding
import helper; reload(helper)
before the from-import. -
Right,
reload
works withmodule objects
— successfully imported before — only … -
Yup. That worked. Thanks!
I'm not a python expert, but is this something unique to pythonista? I've not encountered this before in other IDEs.
-
It's kind of unique to Pythonista – IDEs on other platforms usually run scripts in a separate process, this is technically impossible to do on iOS (at least in an App Store app), so Pythonista runs a single interpreter and imports are cached (which is just how Python works, it's the same on any platform when you use the command-line Python).