So i am making a test coding language and i need to code a goto statement (ik while and for are alternatives but i want to use goto for this) is there a way to go back in the file?
Here is my code:
with open("code.txt", "r") as file:
for line in file:
line = line.split(" ")
if line[0] == "ADD":
cmd.ADD(int(line[1]), int(line[2]), line[3])
elif line[0] == "OUT":
cmd.OUT(line[1])
elif line[0] == "GOTO":
#code for changing lines here (will be in the cmd class if possible)
also just to clarify, cmd is the class holding all the commands
i tried using seek()
but it changes the file pointer for each byte, not line
New contributor
SuperShrew is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.