Help reading binary data from files
Gabriel Genellina
gagsl-py at yahoo.com.ar
Tue Feb 6 17:28:52 EST 2007
En Tue, 06 Feb 2007 19:01:20 -0300, jeff <jeff at kalikstein.com> escribió:
> I am stumped trying to read binary data from simple files. Here is a
> code snippet, where I am trying to simply print little-endian encoded
> data from files in a directory.
>
> for name in os.listdir(DOWNLOAD_DIR):
> filename = s.path.join(DOWNLOAD_DIR, name)
> if os.path.isfile(filename):
> f = open(filename, 'rb')
> while True:
> ele = unpack('<h', f.read(2))[0]
> print ele
>
>
> When the code runs, 0 is always the data printed, but the data files
> are not all zero.
Looks fine to me...
--
Gabriel Genellina
More information about the Python-list
mailing list