4

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

    2 Answers 2

    3

    Use os.environ:

    import os print os.environ['CCDeviceID'] 
    1
    • Works perfect, I had the os.environ part, just hadn't imported OS... will mark as answer when it allows me
      – EdG
      CommentedJun 22, 2014 at 19:53
    3

    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.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.