newbie question about compression and ascii

H

Haim Ashkenazi

Hi

I'm a real newbie, so sorry if this is a trivial question.

I'm writing a script that collect a list of files and creates a zipfile from
these files. when running it on linux everything works fine, but when I'm
running it on windows I get this error when running the command:

myZip.write(file)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa8 in position 10:
ordinal not in range(128)

the file variable contains: u'C:\\Document and Settings\\haim\etc...'.

is there a way to solve this?

thanx
 
S

Serge Orlov

Haim Ashkenazi said:
Hi

I'm a real newbie, so sorry if this is a trivial question.

I'm writing a script that collect a list of files and creates a zipfile from
these files. when running it on linux everything works fine, but when I'm
running it on windows I get this error when running the command:

myZip.write(file)

UnicodeDecodeError: 'ascii' codec can't decode byte 0xa8 in position 10:
ordinal not in range(128)

the file variable contains: u'C:\\Document and Settings\\haim\etc...'.

A unicode file name... Zip format doesn't support unicode file names.
is there a way to solve this?

Only work around. Encode the unicode string using an encoding
of your choice. For windows it's probably "mbcs":
if isinstance(file_name, unicode):
myZip.write(file_name.encode('mbcs'))

-- Serge.
 
H

Haim Ashkenazi

Serge said:
A unicode file name... Zip format doesn't support unicode file names.


Only work around. Encode the unicode string using an encoding
of your choice. For windows it's probably "mbcs":
if isinstance(file_name, unicode):
myZip.write(file_name.encode('mbcs'))
thanx, this seem to solve the problem.

Bye
 

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
474,175
Messages
2,570,946
Members
47,497
Latest member
PilarLumpk

Latest Threads

Top