Parag_AP's blog

By Parag_AP, 18 months ago, In English

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.

Full text and comments »

  • Vote: I like it
  • -5
  • Vote: I do not like it