On Tue, Jul 5, 2016 at 7:03 PM, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 2016-07-05 23:05, Seymore4Head wrote: >> >> import os >> >> f_in = open('win.txt', 'r') >> f_out = open('win_new.txt', 'w') >> >> for line in f_in.read().splitlines(): >> f_out.write(line + " *\n") >> >> f_in.close() >> f_out.close() >> >> os.rename('win.txt', 'win_old.txt') >> os.rename('win_new.txt', 'win.txt') >> >> >> I just tried to reuse this program that was posted several months ago. >> I am using a text flie that is about 200 lines long and have named it >> win.txt. The file it creates when I run the program is win_new.txt >> but it's empty. >> > Although it creates a file called "win_new.txt", it then renames it to > "win.txt", so "win_new.txt" shouldn't exist. > > Of course, if there's already a file called "win_old.txt", then the first > rename will raise an exception, and you'll have "win_new.txt" and the > original "win.txt". > > -- > https://mail.python.org/mailman/listinfo/python-list
Why don't you comment out the renames, and see what happens? -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list