UnicodeDecodeError: problem when path contain folder start with character 'u
tjreedy at udel.edu
Mon Jun 22 17:45:21 CEST 2009
> I am facing an error on Unicode decoding of path if it contain a folder/file
> name starting with character 'u' .
> Here is what I did in IDLE
> 1. >>> fp = "C:\\ab\\anil"
The results in two single \s in the string.
Use / for paths, even on Windows, and you will have less trouble.
> 2. >>> unicode(fp, "unicode_escape")
why? Not for interacting with file system.
It tries to interpret \s. Not what you want.
> 3. u'C:\x07b\x07nil'
> 4. >>> fp = "C:\\ab\\unil"
This has \u followed by three chars.
\u followed by FOUR chars is a unicode escape
for ONE unicode char.
> 5. >>> unicode(fp, "unicode_escape")
This tries to interpret \uxxxx as 1 char,
but it only fines \uxxx and the string ends.
> 7. Traceback (most recent call last):
> 8. File "<pyshell#41>", line 1, in <module>
> 9. unicode(fp, "unicode_escape")
> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
> 5-9: end of string in escape sequence
Read the doc for string literals and unicode function.
More information about the Python-list