I have some Python code that works as expected if I type the commands one-at-a-time using Python's interactive mode. The same code crashes if saved as myscript.py
and run as 'C:\Python27\python.exe myscript.py'
.
In what ways could running Python code as a script cause it to crash, if the same code works in interactive mode?
This question asks for ways to tell if python is in interactive mode. However, the asker just wants a single, reliable fingerprint of interactive mode. I'd like a list of ways that interactive mode is different, with particular attention to problems this can cause.
For example:
sys.path
could be differentos.getcwd()
could be differentos.environ
could be differentWhat else could be different between Python's interactive and script mode?
It looks like you're interacting with hardware, which brings up the most glaring difference between the REPL and a script:
Commands in a script run immediately as soon as possible, whereas the REPL waits for human input.
That is to say, you are probably having a timing issue where the hardware isn't ready for the next command so soon after executing the previous.