I'm trying to add new information, with several if loops, to a new file with append.() but I'm not sure that this works. The new file will also include some data from the f_file, that is why the if loops are there.
f=open('filename', 'r') new=open('filename', 'w') for data in f.readlines(): if '#' not in data: new.append('notExist' + '\n') if 'SRM' in data: new.append(data + '\n') if '%' in data: new.append(data + '\n') f.close() new.close()
Is this correct? Do I need to add an 'a' instead of 'w' when opening the new file?
Edited 5 Years Ago by sofia85: n/a