简体   繁体   中英

PyCharm debug mode with Python 3

I'm trying to figure out how to determine in code whether I'm in debug mode or not. Basically I've got 2 different configurations that I want to run based on whether I'm in debug mode or not. Basically like this...

if DEBUG:
    a = 1
else:
    a = 2

Is it something in Run > Edit Configurations? I can't quite figure it out.

You can detect PyCharm debugger this way:

import sys
if 'pydevd' in sys.modules:
    pass # debugger detected

Another option (which looks better from my point of view) is to make dfiferent run parameters with different enviroments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM