print("", file=fw) is used instead of fw.write()