Normally you can execute a Python script for example: python myscript.py
, but if you are in the interactive mode, how is it possible to execute a Python script on the filesystem?
>>> exec(File) ???
It should be possible to execute the script more than one time.
myscript.py
have a proper "main" function? Why can't youimport myscript
andmyscript.main()
? That's the usual approach. Why won't that work? Can you fix myscript to add a proper "main" function? – ArgentiferousPYTHONSTARTUP=some_script.py python -i
. This will execute some_script.py and drop you to an interactive shell. If your working script defines local variables, you'll be able to access them from the shell. This can be really handy when trying to experiment with code or analyze behavior after the fact. – Trabzon