Setting $ ENV {variable} when calling python

I am new to Python and would like to reproduce the convenience that I used when working in Perl. When calling a Perl script, I usually set $ ENV variables (e.g. VERBOSE, DEVELOP and DEBUG). Inside the called script, I restore their values ​​using

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

This allows you to print stmts conditionally for these variables.

Can I do the same in Python? I know thanks to the previous answers (thanks!) To use os.environ [var] in the script to access the values. But I could not understand how to assign a value to a variable when I call a script from the command line, as I could when a callinbg Perl script

Can I set values ​​for such variables on the command line that invokes the python script?

TIA

+1
python
source share
1 answer

They are available through the os.environ dictionary.

 os.environ['VERBOSE'] 
0
source share

All Articles