How to evaluate environment variables into a string in Python?

Use os.path.expandvars to expand the environment variables in the string, for example:

>>> os.path.expandvars('$C/test/testing')
'/stackoverflow/test/testing'

Leave a Comment