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

眉间皱痕 提交于 2020-01-16 04:15:45

问题


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


回答1:


They are accessible via the os.environ dictionary.

os.environ['VERBOSE']


来源:https://stackoverflow.com/questions/16316481/setting-envvariable-when-calling-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!