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.
Wrong .py used with Pythonista 3.4 while using Working Copy
-
I’m using Working Copy on iPad Pro to access my Git repository,
Open the Working Copy folder from Pythonista as an external folder
2 scripts: A.py and B.py
Edit and modify B.py
Go to A.py
Modify A.py and launch the application (main in A.py, calling something in B.py)Everything works like nothing was modified in B.py !!! (a cache not flushed? B.py not saved prior to launch the execution of A.py?)
Did you experienced something similar ?
Best regards
Frédéric@omz : Great accomplishment with 3.4 !
-
@ftourand are any of these files in site-packages?
Just to be clear, from A.py, you are including
import B
?The way python imports work, a cached copy is saved in sys.modules['B'], and never reloaded when importing, unless you explicitly call importlib.reload. Since pythonista never restarts the interpreter like you'd have when running python on a desktop, editing files would be annoying since nothing would reload.
Pythonista handles this when you press the play button by: 1) deleting globals, 2) resetting the path and 3) deleting all sys.modules imports unless they are built in to pythonista, or live in site-packages.
If you are working inside site-packages, or if you are importing A from the interactive command line, you will have to reload B manually. The simplest way is probably something like this (inside A)
B= sys.modules.pop('B', [] ) del B import B
That said, the best practice is probably to do your development in a folder that is not within site-packages, until you are happy with the result. Then move to site-packages when it is stable.
-
@JonB : None of the files are in site-package (as fare as I understand : site-package are located in "Python Modules/site-package"
Files are in the "working copy" application area, and integrated in Pythonista using the "External Files" "Open ..." option in the sidebar menu of Pythonista.
Yes I'm including B from A (with import). No I'm not importing A from an interactive command line
I've done another test with files located in iCloud from Pythonista directory
A.pyimport B.B as Be aa = 1 bb = Be.fun(aa) print(bb)
B/B.py
def fun(p): return 1
Execute A > 1 is printed to the console
Edit B.py and change todef fun(p): return p*2.0
Go to A and Execute A > 1 is still printed to the console.
Kill and relaunch Pythonista
Go to A and Execute A > 2.0 is printed to the console.weird ;)
-
@ftourand does anybody tried to reproduce this unexpected behavior ? (2 python files, A and B, simple code).
Thksimport B.B as Be aa = 1 bb = Be.fun(aa) print(bb)
def fun(p): return 1
Execute A.py >> '1' in the console
then modify
B.py asdef fun(p): return p*2.0
go to A.py, execute A.py >> still '1' in the console !?
exit and restart pythonista 3.4
relaunch A.py >> 2.0 in the console -
@ftourand error
Traceback (most recent call last): File "/var/mobile/Containers/Shared/AppGroup/94C45A26-1F47-4486-9539-896F8F44AA91/Pythonista3/Documents/A.py", line 1, in <module> import B.B as Be ModuleNotFoundError: No module named 'B.B'; 'B' is not a package
Works if
import B as Be
And my two scripts A and B are edited in two tabs, and if I change into return p*2, and I run A, I get 2
-
Glad to see a new update, but I'm having the same issue with Pythonista 3.4 and Working Copy. Everything worked fine in the previous version.
-
@cvp said in Wrong .py used with Pythonista 3.4 while using Working Copy:
wo scripts A and B are edited in two tabs, and if
Sorry; I should have emphasize that B was in folder B.
Did you experienced this "file not saved (B), and ran with the previous version"?
-
@ftourand said
Did you experienced this "file not saved (B), and ran with the previous version"?
No, all was ok, with both files in local Pythonista root and a 2nd test in Pythonista iCloud.
But without storing B in a folder named B
Now, tested with B in a B folder and I get the same problem as you...
-
@cvp many thanks … I thought I was the only fan of Pythonista encountering this issue
@omz could you have a look at this basic feature please ? (Flushing cache of files not belonging to the current directory, prior to launch the script of the current file, otherwise you will execute the prior to modification of those files)
@omz many thanks again for this huge delivery (3.4)