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')
val = int(val, 16) + 1
f.write('%02X' % val)
print val
----------------------------------
--> 3043
----------------------------------
f = open('serial.txt', 'r')
val = f.read() print val
val = val+1
----------------------------------
--> TypeError: cannot concatenate 'str' and 'int' objects

----------------------------------
f = open('serial.txt', 'rb')
val = f.read()
val = val + 1
----------------------------------
--> TypeError: cannot concatenate 'str' and 'int' objects


hm....



--
Kindest regards.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to