vendredi 24 avril 2020

if-else with environmental variables

I would like to have an if-else structure that checks if an environmental variable exists, as:

if "ENV_VAR" in os.environ:
    if os.environ["ENV_VAR"] == "one":
        do_something()
    else:
        do_something_else()
else:
    do_something_else()

Is there a better way to write the code, specifically to avoid writing twice the call to "do_something_else()" ?

Aucun commentaire:

Enregistrer un commentaire