0 Members and 1 Guest are viewing this topic.
BTW this is for a processor I'm making, so don't expect to recognize anything.
import systable = {"If":"21", "While":"32", "etc...":"25", ... "For":"91"}input_path = "C:\\Users\\TheGame\\SomeDirectory\\thing.txt"output_path = "C:\\Users\\Lobster\\n_example\\otherthing.txt"# The double slashes are recommended - you don't want to accidentally have a '\n' somewhere.input_file = open(input_path, "r")output_file = open(output_path, "w")for line in input_file: cut = line.index(" ") # This searches for the position of the space replacement = table[line[0:cut]] output_file.write(replacement + line[cut+1:] + "\n") # Just doing line[cut:] would include the space.input_file.close()output_file.close()Print("Done!")