Question about binary file reading
I'm writing a tool to do some binary file comparisons. I'm opening the file using fd=open(filename,'rb') # Need to seek to 0x80 (hex 80th) location fd.seek(0x80) # Need to read just 8 bytes and get the result back in hex format. x=fd.read(8) print x This prints out garbage. I would like to know what am i missing here. Basically, I am trying to read 8 bytes from location 0x80 from a binary file called "filename" Any tips/inputs are welcome. thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about binary file reading
k,thanks all. l=map(lambda x: '%02x' %ord(x),d) s=string.join(l,sep='') PS#. Endedup learning little bit of Lambda functions. :-) Scott David Daniels <<< Thanks for your wisdom about the "spaces". Its a 3 liner code-snippet! -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about binary file reading
On Mar 5, 9:24 am, Marco Mariani wrote:
> vibgyorbits wrote:
> > l=map(lambda x: '%02x' %ord(x),d)
> > s=string.join(l,sep='')
>
> > PS#. Endedup learning little bit of Lambda functions. :-)
>
> That's so 2007...
>
> The 2.5-esque way to write that is
>
> s = ''.join('%02x' % ord(x) for x in d)
Yes..:-) I totally agree..still learning some new stuff. SOme of you
folks are really good.
thanks again.. Although, next step would be to really get into the
algorithm complexity ,but right now
let me finish my tool & then dig into finer details.
--
http://mail.python.org/mailman/listinfo/python-list
