Using environment variables in Python

I have an environment variable called% CCDeviceID%. When I run a command using python on the command line, I want to be able to use this variable, including% CCDeviceID% in the script does not work. How to implement environment variables in my python script?

Thanks Ed

+4
source share
2 answers

Use os.environ:

import os
print os.environ['CCDeviceID']
+3
source

You can get a list of all the environment variables available to you by simply following these steps:

>>> import os
>>> print os.environ

os.environ - , env , , %. CCDeviceID.

+3

Source: https://habr.com/ru/post/1545588/


All Articles