Блог пользователя Parag_AP

Автор Parag_AP, 2 года назад, По-английски

I was trying to find a something for python that works same as the cpp macro #ifndef ONLINE_JUDGE and finally come up with a solution that is working in my PyCharm IDE.

I have to define a environment variable. My variable is named __DEBUG__ which value is 1. Then I access in code by,

import os

if os.environ.get("__DEBUG__"): #Here __DEBUG__ is the variable name
    #Code for my environment
else:
    #Code for Online Judge

Basically, I use a boolean variable DEBUG for avoiding this whole code in multiple times.

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится