detect interactivity

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Dec 29 19:52:22 EST 2009


On Tue, 29 Dec 2009 16:09:58 +0100, Roald de Vries wrote:

> Dear all,
> 
> Is it possible for a Python script to detect whether it is running
> interactively? It can be useful for e.g. defining functions that are
> only useful in interactive mode.

Ah, I should have looked more carefully at the docs...

http://docs.python.org/library/sys.html#sys.ps1

sys.ps1 and sys.ps2 are documented as only existing if you are running 
interactively.


-- 
Steven



More information about the Python-list mailing list