UnicodeDecodeError: problem when path contain folder start withcharacter 'u

A

aberry

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"
2. >>> unicode(fp, "unicode_escape")
3. u'C:\x07b\x07nil'
4. >>> fp = "C:\\ab\\unil"
5. >>> unicode(fp, "unicode_escape")
6.
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
11. >>>

Not sure whether I am doing something wrong or this is as designed behavior
..
any help appreciated

Rgds,
aberry
 
P

Piet van Oostrum

aberry said:
a> I am facing an error on Unicode decoding of path if it contain a folder/file
a> name starting with character 'u' .
a> Here is what I did in IDLE
a> 1. >>> fp = "C:\\ab\\anil"
a> 2. >>> unicode(fp, "unicode_escape")
a> 3. u'C:\x07b\x07nil'
a> 4. >>> fp = "C:\\ab\\unil"
a> 5. >>> unicode(fp, "unicode_escape")
a> 6.
a> 7. Traceback (most recent call last):
a> 8. File "<pyshell#41>", line 1, in <module>
a> 9. unicode(fp, "unicode_escape")
a> 10. UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position
a> 5-9: end of string in escape sequence
a> 11. >>>
a> Not sure whether I am doing something wrong or this is as designed behavior
a> .
a> any help appreciated

Calling unicode(fp, "unicode_escape") with these filenames is nonsense.
unicode_escape is for transforming a string like \u20ac to a ¤-sign or
vice versa:
¤

So what are you trying to achieve?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top