Environment variables - Expand

Dips dipankarweb at yahoo.co.in
Sat May 17 03:45:28 EDT 2003


Thanks All. The code snippet helped.

I was looking for something like below as Alex Martelli mentioned:

import re
re_env = re.compile(r'%\w+%')

def expander(mo):
    return os.environ.get(mo.group()[1:-1}, 'UNKNOWN')
filename = re_env.sub(expander, filename)




More information about the Python-list mailing list