Detecting interactive mode reliably

M

Matthew Barnes

Surely this has been asked before, but I've not yet found the answer
on Google Groups or the Python FAQ.

Is there a method for reliably detecting whether the interpreter is
running in interactive mode? The best solution I've come up with so
far is to check sys.argv[0] for an empty string or '-c', but I'm not
sure whether that works for all the various Python IDEs out there.

Reason for the question is that I'd like a module I'm writing to run
some extra initialization steps when the module is imported from an
interactive interpreter.

So something like:

if some_reliable_interactive_mode_test():
initialize_for_interactive_use()

Matthew Barnes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top