可能重复:
tell whether python is in -i mode
Tell if python is in interactive mode
有没有办法检查是否已使用交互式选项-i?
运行python脚本e.g。
if interactive_mode:
print 'I am in interactive mode!'
else:
print 'I am in batch mode!'
然后用
打电话python hello_world.py
I am in batch mode!
python -i hello_world.py
>> I am in interactive mode!
答案 0 :(得分:2)
import sys
if sys.flags.interactive:
print 'I am in interactive mode!'
else:
print 'I am in batch mode!'