Is is possible for a python script to know whether it is run with the interactive option '-i'?
Question: > **Possible Duplicate:**  
>  [tell whether python is in -i
> mode](http://stackoverflow.com/questions/640389/tell-whether-python-is-in-i-
> mode)  
>  [Tell if python is in interactive
> mode](http://stackoverflow.com/questions/2356399/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!
    


Answer: 
    import sys
    if sys.flags.interactive:
        print 'I am in interactive mode!'
    else:
        print 'I am in batch mode!'
    

