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)
Y
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)
--
http://mail.python.org/mailman/listinfo/python-list
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
"Benjamin Peterson" wrote:
>So called encodings like "hex" and "rot13" are abuse of
>encode() method. encode() should translate
>between byte strings and unicode, not preform
>transformations like that. This has been removed
>in 3.x, so you should use binascii.
When all else fails, and just for
Benjamin Peterson wrote:
John Machin lexicon.net> writes:
On Mar 5, 12:13 pm, Benjamin Peterson wrote:
import binascii
print binascii.hexlify(some_bytes)
AFAICT binascii.hexlify(some_bytes) gives the SAME result as
some_bytes.encode("hex") for much more typing -- I see no
"better"
here.
So
John Machin lexicon.net> writes:
> On Mar 5, 12:13 pm, Benjamin Peterson wrote:
> >
> > import binascii
> > print binascii.hexlify(some_bytes)
>
> AFAICT binascii.hexlify(some_bytes) gives the SAME result as
> some_bytes.encode("hex") for much more typing -- I see no
> "better"
> here.
So calle
On Mar 5, 12:13 pm, Benjamin Peterson wrote:
> Tino Wildenhain wildenhain.de> writes:
>
> > Rhodri James wrote:
> > > for b in x:
> > > print hex(ord(b))
>
> > better:
>
> > print x.encode("hex")
>
> even better:
>
> import binascii
> print binascii.hexlify(some_bytes)
AFAICT binascii.hexlif
vibgyorbits wrote:
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 print
Tino Wildenhain wildenhain.de> writes:
> Rhodri James wrote:
> > for b in x:
> > print hex(ord(b))
> >
>
> better:
>
> print x.encode("hex")
even better:
import binascii
print binascii.hexlify(some_bytes)
--
http://mail.python.org/mailman/listinfo/python-list
On Mar 5, 10:51 am, "Rhodri James"
wrote:
> On Wed, 04 Mar 2009 23:28:32 -, Tino Wildenhain
> wrote:
>
>
>
> > Rhodri James wrote:
> >> On Wed, 04 Mar 2009 22:58:38 -, vibgyorbits
> >> wrote:
>
> >>> I'm writing a tool to do some binary file comparisons.
> >>> I'm opening the file us
I just found a well-hidden part of the behaviour you expected.
vibgyorbits writes:
> # Need to read just 8 bytes and get the result back in hex format.
> x=fd.read(8)
> print x
Why would this print the bytes in hex format? “Convert to hexadecimal”
is not the default text encoding for ‘print’.
vibgyorbits writes:
> 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
On Wed, 04 Mar 2009 23:28:32 -, Tino Wildenhain
wrote:
Rhodri James wrote:
On Wed, 04 Mar 2009 22:58:38 -, vibgyorbits
wrote:
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
Rhodri James wrote:
On Wed, 04 Mar 2009 22:58:38 -, vibgyorbits wrote:
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 i
On Wed, 04 Mar 2009 22:58:38 -, vibgyorbits wrote:
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.re
On Wed, Mar 4, 2009 at 2:58 PM, vibgyorbits wrote:
> 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
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 kno
17 matches
Mail list logo