Tell me, please, how to do the following: there is a file, there are two lists, in one the current values that are in the file, the other with new values that need to be replaced with the current one, has actually written the following function:
def createMapFile(old_data, new_data, file): try: if len(old_data) != len(new_data): print 'Наборы параметров не соответствуют друг-другу' else: file = open(file, 'r') # Opens the file in read-mode text = file.read() # Reads the file and assigns the value to a variable file.close() # Closes the file (read session) file = open(mapfile, 'w') i = 0 f = [file.write(text.replace(old_data[i], new_data[i])) for i in range(1, old_data)] # file.write(text.replace(old_data[i], new_data[i])) #replaces all instances of our keyword return file.close() # Closes the file (write session) except: print 'Ошибка:' Now an error occurs, although if you take a list and remove the for loop, replacing it with a commented line, then everything works, but with one word, you need a list of words.