如果我处于调试模式,我想要做其他的事情,而不是当我不在时。如何检查是否从脚本中设置了python调试选项
if DEBUG:
STORED_DATA_FILE = os.path.join(TEMP_DIR, 'store.dat')
LOG_LEVEL = logging.DEBUG
print "debug mode"
else:
STORED_DATA_FILE = os.path.join(SCRIPT_PATH, 'store.dat')
LOG_LEVEL = logging.INFO
print "not debug mode"
则:
python script.py
not debug mode
python -d script.py
debug mode
如何检测呢?它当然不使用__debug__
变量。
那么,以澄清以下问题。我真正想做的就是从一般环境中获取一些信息,但我尝试设置一个环境变量并在os.environ中查找它,但这并不总是奏效。 – user132262 2009-10-20 09:48:40
与'-d'选项无关:[Python:How to detect debug interpreter](http://stackoverflow.com/questions/646518/python-how-to-detect-debug-interpreter) – jfs 2012-11-12 22:47:24
http:// stackoverflow。 com/questions/27748132/is-there-a-flag-i-can-check-in-my-code-see-if-pycharms-debugger-is-running?answertab = active#tab-top 这个答案适合我。 – 2015-09-15 08:07:36