0

Possible Duplicate:
tell whether python is in -i mode
Tell if python is in interactive mode

Is there a way to check whether a python script has been run with the interactive option -i?

e.g.

if interactive_mode:
    print 'I am in interactive mode!'
else:
    print 'I am in batch mode!'

Then call with

python hello_world.py
I am in batch mode!

python -i hello_world.py
>> I am in interactive mode!
Community
  • 1
  • 1
scruffyDog
  • 721
  • 3
  • 7
  • 17

1 Answers1

2
import sys
if sys.flags.interactive:
    print 'I am in interactive mode!'
else:
    print 'I am in batch mode!'
horejsek
  • 1,378
  • 14
  • 8