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 = f.read
Of course - my apologies, I was being an idiot.
On Thu, 20 Aug 2009 14:38:08 -0700, Simon Forman
wrote:
On Aug 20, 5:18 pm, "Rami Chowdhury" 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,
[fixed top-posting]
Rami Chowdhury wrote:
On Thu, 20 Aug 2009 14:08:34 -0700, 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:
On Aug 20, 5:18 pm, "Rami Chowdhury" 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 string. hex C => decim
On Aug 20, 5:08 pm, 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 = op
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 = f.read
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
wrote:
Hello guys
I w
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')
p