Finding out that Python is in interactive mode in sitecustomize.py

Carey Evans careye at spamcop.net
Sun Dec 30 09:46:02 CET 2001


joonas at olen.to (Joonas Paalasmaa) writes:

> For some reason it doesn't work in sitecustomize.py .
> When these lines are to sitecustomize.py 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 sitecustomize.py 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 sitecustomize.py:

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

-- 
	 Carey Evans  http://home.clear.net.nz/pages/c.evans/



More information about the Python-list mailing list