Access system environment variables
Access system environment variables
import os# w w w .j ava 2s. co m
def print_system_info() :
print "Environment strings:"
for e in os.environ :
print e
print_system_info()
The code above generates the following result.
os.environ
contains a dictionary of environmental variables.
import os
print os.environ['PATH']
Iterating Through Environment Items
import os # from w ww. j a v a2 s. c o m
for k, v in os.environ.items():
print "%s=%s" % (k, v)
print "\n".join(["%s=%s" % (k, v) for k, v in os.environ.items()])
The code above generates the following result.