如果我處於調試模式,我想要做其他的事情,而不是當我不在時。如何檢查是否從腳本中設置了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