#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Brisbane, Australia
    Posts
    12
    Rep Power
    0

    Python, wxPython and Unicode errors


    Hi there,

    I'm implementing a recursive file search in Python (in Windows XP, latest versions of wxPython and Python) and have come across a particularly frustrating Unicode exception in a completely unexpected place ...

    File "....\search\Search.py", line 312, in __search_directory_recurse
    results.extend( self.__search_directory_recurse( full_path, pattern, re_mode, flags ) )
    File ".....\search\Search.py", line 304, in __search_directory_recurse
    for fname in outfiles:
    UnicodeError: ASCII decoding error: ordinal not in range(128)

    How can a for loop cause a UnicodeError?

    Also, I get the exact same error (same type, different location) if I try to print messages to standard output at too great a rate (from within a for loop, presumably because wxPython catches output in the special stdout window, and I'm guessing that the toes of GUI threads are getting trampled - but a UnicodeError??).

    If anyone could offer some insight as to what would cause the former error to occur, please let me know.

    Thanks!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Brisbane, Australia
    Posts
    12
    Rep Power
    0
    Problem fixed with a bit of a hack:

    The problem, as the error indicated, was with the following line

    for fname in outfiles:

    I replaced it with a while loop, using an integer index into outfiles, and the error disappeared.

    Still not sure what was going on.

    - Tom
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    France
    Posts
    53
    Rep Power
    14
    I don't think the Unicode error doesn't come from the loop you use but from your fname variable. This is typically the kind of error you get when you create a string variable that contain an invalid character (for example a letter with an accent).

    To solve this problem, you'll certainly have to use the unicode() function. But I don't know much more...

    I suggest you print all the filenames that you treat and try to see which filename causes the Unicode exception. It surely contains an invalid ascii character.

IMN logo majestic logo threadwatch logo seochat tools logo