Finding out that Python is in interactive mode in

Carey Evans careye at
Sun Dec 30 03:46:02 EST 2001

joonas at (Joonas Paalasmaa) writes:

> For some reason it doesn't work in .
> When these lines are to and Python is started in
> interactive mode, Python prints "In non-interactive mode".


Looking closer, it looks like sys.ps1 is set up just before the
interactive loop is started, but after is imported.

Given this, the easiest solution looks like the PYTHONSTARTUP
environment variable.  The file this points to is only executed for an
interactive session.  You could set this for all users in a global
shell startup file, or just set it from

  import os
  os.environ['PYTHONSTARTUP'] = '/path/to/'

	 Carey Evans

More information about the Python-list mailing list