Hi, I've noticed that if I have pythonista_startup.py in site_packages folder of Pythonista 3, the code inside it is not executed instantly, while when I had the old Pythonista 2 the file was executed instantly.
Purpose: when I close Pythonista 3 through the typical way of the iPhone (HOME key and swipe the app) and reopen it, I'd like to see the instant execution of the pythonista_startup.py file, that for me is very simple:
and it opens the console/output page of Pythonista, so I can start to use the interactive console immediately without swipe the screen with the fingers.
Well, with old version of Pythonista 2 the code was executed every time and instantly, with new version of Pythonista 3 the same code is not executed always instantly, and I must open some files with the builtin file browser to have the pythonista_startup.py execution.
Question: have you same experience about this? is it something normal or it can be solved?
You could try changing your code to be valid Python 3:
Hi, but it is not a problem about compatibility between python 2 and python 3.
I changed my simple pythonista_startup.py as you suggested, but try to perform the following step to experience my question:
- in site-packages folder (general folder, no site-packages-2 or site-packages-3) there is the following 'pythonista_startup.py' file:
#!python3 print ('Python')
- open the file 'Welcome.md' in the text editor of Pythonista (this file is in the main Pythonista 3 folder)
- close Pythonista 3 app in iOS way
- open Pythonista 3 app: the first page showed is the file 'Welcome.md' previous opened, the app doesn't execute 'pythonista_startup.py'
- if you try to open in the editor another python source file, then the app executes the startup file.
Can you reproduce this? So it is normal?
Hi ccc, have you experienced the not execution of pythonista_startup.py if you have previous opened a not .py file, like a .txt or a .md in the editor?
This seems to be a bug.
pythonista_startupis executed as part of the interpreter's initialization, and if no Python file is opened, the interpreter isn't needed yet, so it doesn't get initialized immediately when the app is launched.
Ok thank you omz for reply. My big project (that will be useful for me and maybe for someone else, but I’m in a very primitive stage. Does it exist something similar?) is to write a python code for Pythonista, using only python libraries built-in Pythonista 3, that:
- is executed every time user opens Pythonista, hence the importance of ‘pythonista_startup.py’ for my project,
- opens instantly a graphical window on which user finds some keys to be touched to execute some main programs, for example:
o key for running a symbolic calculator (via sympy), that opens a graphical calculator with which it is possible to do symbolic math,
o key that opens the built-in python console,
o key that opens built-in file editor with a blank file ready to be edited and tested and with a default name, for example ‘test_1.py’,
o key that opens built-in file browser at a default position, for example at main folder ‘Documents’ (where user can find all the Pythonista main folders)
o key that opens shell console StaSh
For now I don’t know how to allow the return to the main graphical window from console, StaSh, file browser, etc..
Now I’m interested in programming a default code for ‘pythonista_startup.py’ (in my spare time), to be easly modified in the future, that can run, through the touch of some graphical keys, some main programs like the examples above.
Thanks if you will resolve this thing to allow the execution of ‘pythonista_startup.py’ every time and instantly when user opens a new execution of Pythonista app.
Would it perhaps be easier if you made a normal script and added it as a home screen icon (from the wrench menu)? Then you don't need to rely on how
pythonista_startupexecutes. It also makes it easy to open Pythonista without running your app, by force-quitting Pythonista and then running it normally, instead of using the home screen icon for your app. (There is also a way to open Pythonista without running
pythonista_startup, by typing pythonista:// into the Safari address bar. But two separate home screen icons are probably more convenient.)
Hi dgelessus, thanks very much for your hint, it is the best solution and now I know a new feature of Pythonista! It is a so good solution that 'pythonista_startup.py' is always executed in this way because, like omz said, that file is executed after (or during) interpreter's initialization, that starts with every pyhton script execution like the 'shortcuts' that user can create on HOME screen of device.