UnicodeDecodeError: problem when path contain folder start withcharacter 'u

aberry aberry at aol.in
Tue Jun 23 13:32:08 CEST 2009


thanks all for help...
actually this was in old code having 'unicode_escape' .
i hope it was there to handle path which may contain localized chars...

but removing unicode_escape' it worked fine... :)

rgds,
aberry


Mark Tolonen-3 wrote:
> 
> 
> "aberry" <aberry at aol.in> wrote in message 
> news:24146775.post at talk.nabble.com...
>>
>> 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
> 
> What is your intent?  Below gives a unicode strings with backslashes.  No 
> need for unicode_escape here.
> 
>>>> fp = "C:\\ab\\unil"
>>>> fp
> 'C:\\ab\\unil'
>>>> print fp
> C:\ab\unil
>>>> unicode(fp)
> u'C:\\ab\\unil'
>>>> print unicode(fp)
> C:\ab\unil
>>>> u'C:\\ab\\unil'
> u'C:\\ab\\unil'
>>>> print u'C:\\ab\\unil'
> C:\ab\unil
> 
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

-- 
View this message in context: http://www.nabble.com/UnicodeDecodeError%3A-problem-when-path-contain-folder-start-with-character-%27u-tp24146775p24164207.html
Sent from the Python - python-list mailing list archive at Nabble.com.




More information about the Python-list mailing list