Sep-01-2020, 10:44 AM
(This post was last modified: Sep-01-2020, 10:44 AM by MysticLord.)
https://docs.python.org/3/library/functions.html#open
edit
Also how would I convert a string "7F" or "1A" from a string representation of a hexadecimal number into a decimal number?
double edit
I think this should work for the last question.
Quote:The default mode is 'r' (open for reading text, synonym of 'rt'). Modes 'w+' and 'w+b' open and truncate the file. Modes 'r+' and 'r+b' open the file with no truncation.Which do I use if I want to seek within a file in binary mode, write to it in an overwrite rather than insertion mode, and close it?
edit
Also how would I convert a string "7F" or "1A" from a string representation of a hexadecimal number into a decimal number?
double edit
I think this should work for the last question.
int("7F",16) int("1A",16) int(lineList[3][n:n+1],16)Here's the code for my script.
import sys,io csvName = sys.argv[1] with open(csvName, "r") as f: line = f.readline() while line != '': lineList = line.split(',') with open(lineList[0],"w+b") as writeFile: #waiting on python forum reply for above writeFile.seek(int(lineList[1])) #next do a loop where you grab lineList[3][n:n+1], #convert it from a hex string to an int, #and write it. #maybe int(lineList[3][n:n+1],16) line = f.readline() #file.seek(36,0) #address = file.read(1)[0] #address = ((file.read(1)[0] << 8) | address) #address = ((file.read(1)[0] << 16) | address) #address = ((file.read(1)[0] << 24) | address) #print(str(address)) #print(hex(address)) #open csv file #while (readfirstline() != EOF) #{ # split line along commas # open file in first element in array or list as write binary # seek to addresss in second element in array or list # convert third line into format writable to binary file # write third line # close file #} #just operating on one file, don't need this for loop or wildcards