Re: incrementing string/hex value from file and write back

2009-08-20 Thread Dave Angel
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

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Rami Chowdhury
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,

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Ethan Furman
[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:

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Simon Forman
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

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Simon Forman
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

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Mark Lawrence
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

Re: incrementing string/hex value from file and write back

2009-08-20 Thread Rami Chowdhury
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

incrementing string/hex value from file and write back

2009-08-20 Thread Matthias Güntert
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