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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aberry
    New Member
    • Sep 2008
    • 10

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

    I am facing an error on Unicode decoding of path if it contain a folder/file name starting with character 'u'

    Code:
    >>> fp = "C:\\ab\\anil"
    >>> unicode(fp, "unicode_escape")
    u'C:\x07b\x07nil' 
    >>> fp = "C:\\ab\\unil"
    >>> unicode(fp, "unicode_escape")
    
    Traceback (most recent call last):
      File "<pyshell#41>", line 1, in <module>
        unicode(fp, "unicode_escape")
    UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 5-9: end of string in escape sequence
    >>>
    I am not sure what is causing this error.
    any help appreciated

    Rgds,
    aberry
  • YarrOfDoom
    Recognized Expert Top Contributor
    • Aug 2007
    • 1243

    #2
    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.

    Comment

    Working...