Change of mass hexa data - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Change of mass hexa data (/thread-20459.html) |
Change of mass hexa data - kosteloos - Aug-12-2019 hello there to be brief I would like to change 6 hexa characters but in several files I explain myself I designed this code: fichier1 = "fichier.dat" with open(fichier1, "rb") as fs: contenu = fs.read() # le contenu est de type "bytes" (=octets) octet1 = bytes.fromhex('7AEB02') # octet à chercher octet2 = bytes.fromhex('7AEB03') # octet à mettre à la place index = contenu.find(octet1) if index<0: print("Octet non trouvé!") else: print("Octet cherché se trouve à l'index:", index) contenu = contenu[:index] + octet2 + contenu[index+1:] fichier2 = "fichier2.dat" with open(fichier2, "wb") as fd: fd.write(contenu)the.dat file contains 7AEB02 then replace with 7AEB03 and write the new file to file2.dat roughly the next step is to re-open file2.dat and increment the hexa value of 1 is to write it in file3.dat ect........ I'm locked on a loop apparently. thank you in advance for your help |