Connecting Tech Pros Worldwide Help | Site Map

UnicodeDecodeError: problem when path contain folder start with character 'u'

  #1  
Old June 22nd, 2009, 07:53 AM
Newbie
 
Join Date: Sep 2008
Posts: 10
I am facing an error on Unicode decoding of path if it contain a folder/file name starting with character 'u'

Expand|Select|Wrap|Line Numbers
  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. >>> 
  12.  
I am not sure what is causing this error.
any help appreciated

Rgds,
aberry
  #2  
Old June 23rd, 2009, 10:41 PM
YarrOfDoom's Avatar
Expert
 
Join Date: Aug 2007
Location: Belgium
Posts: 1,107

re: UnicodeDecodeError: problem when path contain folder start with character 'u'


I'm guessing it's seeing \unil as Unicode-Escape encoding.

On that page is also an explanation of how to use a string's encode-function, which might be better suited in this case.
Reply