I am currently coding a tool for my work that modifies a textfile by removing unneeded parts of a string at specific spots in the file. I would like to know if there are any obvious things I am missing or doing too complicated. I know that some of the comments are considered too long for PEP8.
class vis_file_tools: def __init__(self): pass # Splits the input line into list (by a space), removes the last position, joins them with spaces and returns the modified line. def remove_jedec_line(self, input_line): input_line_split = input_line.split(" ") # splits the string that was input through the function into a list del input_line_split[-1] # deletes the last line from the list (In this case it removes the jedec) output_line = " ".join(input_line_split) # joins back the list to a string. Joins the list with a space output_line = output_line + "\n" return output_line # returns the finished string to the caller of the function def remove_jedecs_file(self, path_input_file, path_output_file): with open(path_input_file, "r") as file: # Opens the input file read only temp_data = "" comp_line_reached = False for line in file: # "line" in this case is already a variable. Do not us file.readline() when using the "for line" loop. if "COMP" in line: # Sets the bool "comp_line_reached" to "true" when the loop reaches the "COMP" in the .vis file which marks the start of the components comp_line_reached = True temp_data = temp_data + line elif comp_line_reached is False: # Simply writes the lines from the file into a variable until the component part is reached. temp_data = temp_data + line else: line_no_jedec = self.remove_jedec_line(line) temp_data = temp_data + line_no_jedec with open(path_output_file, "w") as write_file: write_file.write(temp_data) temp_data = "" # Empties memory