I am using two if conditions in the below code snippet. disable_env value can be passed as a parameter to a function or as an environment variable. Is there a more efficient way to do this in Python using a single if statement?
def func(disable_env=False):
if os.environ.get("DISABLE_ENV"):
disable_env=True
if not disable_env:
print("something")
if not (disable_env := os.environ.get("DISABLE_ENV")): print("something")using Assignment Expressionsif 'DISABLE_ENV' not in os.environ and not disable_env: print('something')print("something" if not os.environ.get("DISABLE_ENV") else "")