Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Change of mass hexa data
#1
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 Smile
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 288 Apr-18-2024, 09:55 PM
Last Post: deanhystad
Question Change elements of array based on position of input data Cola_Reb 6 2,137 May-13-2022, 12:57 PM
Last Post: Cola_Reb
  How to do a mass replace within a CSV file? cubangt 9 5,394 May-09-2022, 06:52 PM
Last Post: snippsat
  Showing data change korenron 10 2,569 Mar-20-2022, 01:50 PM
Last Post: korenron
  Conversion from hexa to decimal in loop bugging Personne 1 1,275 Feb-22-2022, 04:32 AM
Last Post: deanhystad
  So, a mass of errors trying to run a zipline-dependant program on 3.5 env Evalias123 2 2,413 Jan-21-2021, 02:22 AM
Last Post: Evalias123
  Write the XML file from elementtree with hexa decimal encoding Dillibabu 4 3,488 Dec-24-2019, 10:10 AM
Last Post: Dillibabu
  change source from csv data to gsheet Tummerke 1 2,095 May-21-2019, 05:16 AM
Last Post: heiner55
  Mass load images Linuxdesire 1 2,232 Mar-29-2019, 06:24 PM
Last Post: Larz60+
  mass rename files in folders kerzol81 5 9,115 Dec-29-2017, 09:08 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020