file / string problem?

Hans Nowak hnowak at cuci.nl
Fri Mar 24 01:11:49 EST 2000


On 24 Mar 00, at 0:27, Todd Palmer wrote:

> I new to python and I'm having a problem writing a binary string to a
> file.  I'm using the zipfile.py module and getting the data from the zip
> file and writing it to a file object.  The string returned from the
> zipfile.read() function is the correct size, but when I write it to disk,
> the file on the disk is the wrong size and corrupted.  Any ideas?  Do I
> have to do something special with binary data in strings?
> 
> Code:
> 
> import zipfile
> 
> z = zipfile.ZipFile('D:\\tmp\\esbdates.zip')
> try:
>  # read the binary data into a string
>    S = z.read('esbdates.hlp')
>  # note len(S) here returns 362588 which is correct  as per 
>  # zipfile.py AND winzip
>  f = open('D:\\tmp\\esbdates.hlp', 'w')

Try 'wb' rather than 'w'...

Blessed be,

--Hans Nowak (zephyrfalcon at hvision.nl)
Homepage: http://www.hvision.nl/~ivnowa/newsite/
Python questions? See http://tor.dhs.org/~zephyrfalcon/snippets
You call me a masterless man. You are wrong. I am my own master.




More information about the Python-list mailing list