Hello guys
I would like to read a hex number from an ASCII file, increment it and
write it back.
How can this be performed?
I have tried several approaches:
my file serial.txt contains: 0C
--
f = open('serial.txt', 'r')
val = f.read()
val = val.encode('hex')
val = val.encode('hex')
That's the crucial line -- it's returning a new integer, which you are
re-binding to val. If you then did:
val = val + 1
you'd be fine, and could then write val back to your file :-)
On Thu, 20 Aug 2009 14:08:34 -0700, Matthias Güntert
matzeguent...@gmx.de
Matthias Güntert wrote:
Hello guys
I would like to read a hex number from an ASCII file, increment it and
write it back.
How can this be performed?
I have tried several approaches:
my file serial.txt contains: 0C
--
f = open('serial.txt', 'r')
val =
On Aug 20, 5:08 pm, Matthias Güntert matzeguent...@gmx.de wrote:
Hello guys
I would like to read a hex number from an ASCII file, increment it and
write it back.
How can this be performed?
I have tried several approaches:
my file serial.txt contains: 0C
On Aug 20, 5:18 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote:
val = val.encode('hex')
That's the crucial line -- it's returning a new integer, which you are
re-binding to val. If you then did:
No, it returns another string, which still isn't the decimal
representation of the hex
[fixed top-posting]
Rami Chowdhury wrote:
On Thu, 20 Aug 2009 14:08:34 -0700, Matthias Güntert
matzeguent...@gmx.de wrote:
Hello guys
I would like to read a hex number from an ASCII file, increment it and
write it back.
How can this be performed?
I have tried several approaches:
my file
Of course - my apologies, I was being an idiot.
On Thu, 20 Aug 2009 14:38:08 -0700, Simon Forman sajmik...@gmail.com
wrote:
On Aug 20, 5:18 pm, Rami Chowdhury rami.chowdh...@gmail.com wrote:
val = val.encode('hex')
That's the crucial line -- it's returning a new integer, which you are
Matthias Güntert wrote:
Hello guys
I would like to read a hex number from an ASCII file, increment it and
write it back.
How can this be performed?
I have tried several approaches:
my file serial.txt contains: 0C
--
f = open('serial.txt', 'r')
val =