odd unicode error

T

tubby

This:

for root, dirs, files in os.walk(search_path):
for f in files:
print f

###############

Produces this:

Traceback (most recent call last):
File "/home/brad/Desktop/my_script.pyw", line 340, in -toplevel-
hunt(target_files(search_path, skip_file_extensions(),
skip_files()), path_to_results)
File "/home/brad/Desktop/my_script.pyw", line 161, in target_files
for root, dirs, files in os.walk(search_path):
File "os.py", line 291, in walk
for x in walk(path, topdown, onerror):
File "os.py", line 291, in walk
for x in walk(path, topdown, onerror):
File "os.py", line 281, in walk
if isdir(join(top, name)):
File "posixpath.py", line 65, in join
path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1:
ordinal not in range(128)

##################

I'm running Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02)
[GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2

Any ideas? I can't catch this with try/except and using unicode(f)
doesn't help either.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 1:
ordinal not in range(128)

Any ideas?

path is a Unicode string, b is a byte string and contains the
byte \xd0.

The problem is that you have a directory with file names in it that
cannot be converted to Unicode strings, using the file system
encoding. If you can't fix the file system, you have to make
search_path a byte string.

Regards,
Martin
 
T

tubby

Martin said:
path is a Unicode string, b is a byte string and contains the
byte \xd0.

The problem is that you have a directory with file names in it that
cannot be converted to Unicode strings, using the file system
encoding. If you can't fix the file system, you have to make
search_path a byte string.

Regards,
Martin

I fixed it... I didn't tell the whole story. The interface uses
wxpython. It returns a unicode pathname that os.walk() uses. I changed
that pathname with str() and now, it no longer barfs.
 

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

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top