setting $ENV{variable} when calling python [duplicate]
Asked Answered
W

1

1

I'm new to Python and would like reproduce a convenience I used when working in Perl. When calling a Perl script I usually set some $ENV variables (like VERBOSE, DEVELOP and DEBUG). Inside the called script I recover their values using

my $verbose=$ENV{VERBOSE};
my $develop=$ENV{DEVELOP};
my $debug=$ENV{DEBUG};

This allow print stmts conditional on these variables.

Can I do the same thing in Python? I know thanks to previous responses (Thank you!) to use os.environ[var] within the script to access the values. But I have not been able to figure out how to assign a value to a variable when I call the script from the command line as I could when callinbg a Perl script

Can values be set for such variables on the commandline invoking a python script?

TIA

Westwardly answered 1/5, 2013 at 10:29 Comment(0)
U
0

They are accessible via the os.environ dictionary.

os.environ['VERBOSE']
Uncritical answered 1/5, 2013 at 10:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.