| [ Web Proxy ] |
| Viewing: https://wiki.python.org/moin/../python/platforms/../../python/archive/EnvironmentVariables.html | [Back] [Original] |
Legacy Wiki Page
This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.
1 globals().update(os.environ) # Import environment
2
3
4 def replace_w_global_value(mo):
5 key = mo.group(0)
6 without_dollar = key[1:]
7 return str(globals().get(without_dollar, key))
8
9
10 def subs(input):
11 """Perform Bash-like substitutions.
12
13 Any "$FOO" in a string will be replaced with the value of FOO.
14 If it's not defined, it stays as it was: "$FOO".
15 """
16 return re.sub('[$][A-Za-z_]+', replace_w_global_value, input)
The only question I have is: Is there a way to make all assignments within the module, automatically call os.putenv?
So, intercept assignment with [setattr] or something, on the module.
I dont know how to get a handle to the current module, though.
LionKimbro 2005-12-16 20:37:07
Back to top2026, Python Software Foundation
Made with Sphinx and Shibuya theme.
| Web Proxy Viewer | New URL | Original Page |