EdG
EdG

Reputation: 190

Using environment variables in Python

I have an environment variable called %CCDeviceID%. When I run a command using python in Command Prompt, I want to be able to use this variable, and including %CCDeviceID% in the script doesn't work. How can I implement environment variables into my python script?

Thanks Ed

Upvotes: 4

Views: 184

Answers (2)

Martin Konecny
Martin Konecny

Reputation: 59571

You can get a listing of all environment variables available to you simply by doing the following:

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

os.environ is a dictionary mapping env variable name to its value In your case, you probably need to omit the % symbols. To get CCDeviceID.

Upvotes: 3

NPE
NPE

Reputation: 500167

Use os.environ:

import os
print os.environ['CCDeviceID']

Upvotes: 3

Related Questions