Nov-09-2017, 08:02 AM
I have a question related to my code.
I have a text file name data.txt, i put two line it will help me add 1 and transfer to hex.
Right now i meet this two problem.
1. It cn only read one line, if i put two line it will be error
2. It should be able to erase previous data, but it didn't
Do anyone know what i need to changed.
data.txt
11
12
Expected output should be :
0X12
0x13
but right now it can only be used one line, if i put one line it will only pritn like this
110x11
i iwish to pritn only 0x12.
Do anyone know what i need to changed?
I have a text file name data.txt, i put two line it will help me add 1 and transfer to hex.
Right now i meet this two problem.
1. It cn only read one line, if i put two line it will be error
2. It should be able to erase previous data, but it didn't
Do anyone know what i need to changed.
data.txt
11
12
Expected output should be :
0X12
0x13
but right now it can only be used one line, if i put one line it will only pritn like this
110x11
i iwish to pritn only 0x12.
Do anyone know what i need to changed?
with open(r'data.txt','r+') as f:
for line in f:
line = line.strip()
#line = line[:-1] + str(int(line[-1:]) + 1)
line = int(line,16)+1
#f.write ((hex(line).rstrip("L").lstrip("0x") or "0")+'\n')
f.write (hex(line))
#print hex(line).rstrip("L").lstrip("0x") or "0"
