For the benefit of future readers of the code, it might be worth adding a comment, something like:
# ps1 exists if the python interpreter is running in an interactive console;
# sys.flags.interactive is true if a script is being run via "python -i".