It's a compiled C extension, not pure Python, so you generally can't simply copy the DLL/so file across from one installation to another: the Python binary interface changes on 0.1 version number updates (but not 0.0.1 updates). In any case, _winreg seems to be statically build into Python.exe on the current official Windows builds rather than being dropped into the ‘DLLs’ folder.
_winreg.ExpandEnvironmentStrings
is not available pre-2.6, but you could usefully fall back to os.path.expandvars
, which does more or less the same thing. (It also supports $VAR variables, which under Windows you might not want, but this may not be a practical problem.) You're right: %-syntax for expandvars under Windows was only introduced in 2.6, how useless. Looks like you'll need the below.
If the worst comes to the worst it's fairly simple to write by hand:
import re, os
def expandEnvironmentStrings(s):
r= re.compile('%([^%]+)%')
return r.sub(lambda m: os.environ.get(m.group(1), m.group(0)), s)
Though either way there is always Python 2.x's inability to read Unicode envvars to worry about.