[issue6815] UnicodeDecodeError in os.path.expandvars

Brian Curtin report at bugs.python.org
Sat Mar 6 17:26:29 CET 2010


Brian Curtin <curtin at acm.org> added the comment:

FWIW, _winreg.ExpandEnvironmentStrings does the right thing.

D:\python-dev\trunk>PCbuild\amd64\python.exe
Python 2.7a3+ (trunk, Feb 23 2010, 20:22:24) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, sys, _winreg
>>> os.environ["TEST"] = u"jalape\xf1o".encode(sys.getfilesystemencoding())
>>> print(os.path.expandvars(u"C:\\%TEST%"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\python-dev\trunk\lib\ntpath.py", line 354, in expandvars
    res = res + os.environ[var]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf1 in position 6: ordinal
not in range(128)
>>> print(_winreg.ExpandEnvironmentStrings(u"C:\\%TEST%"))
C:\jalapeño

----------
nosy: +brian.curtin

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6815>
_______________________________________


More information about the Python-bugs-list mailing list