1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
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) |
Partager