How do I access windows environment variables using Python?

eg. if I have the following: set junk=C:\temp\junk
how do I access 'junk' from python?

Recommended Answers

All 2 Replies

os.environ['junk']

should do it.

Type:

import os
os.system("set")

To view the system variables.
To use one of them you just:

import os
os.system("%variable%")

This works with windows, but nothing else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.