On Mon, 25 Apr 2016 21:26:34 +0000 (UTC), John Gordon <gor...@panix.com> wrote:
>In <27nshbp40p1llr231dqm31p754tvurk...@4ax.com> Seymore4Head ><Seymore4Head@Hotmail.invalid> writes: > >> On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head >> <Seymore4Head@Hotmail.invalid> wrote: > >> I am going to forget using a directory path. >> I would like to take the file win.txt and append a space and the * >> symbol. > >> f = open('win.txt', 'r+') >> for line in f: >> f.read(line) >> f.write(line+" *") > >> This doesn't work. Would someone fix it please? It is for a task I >> am trying to accomplish just for a home task. > >It's much easier to create a new file and then rename it afterwards, >instead of rewriting the original file. > > 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') That is 100% spoon fed code and that is what I wanted. Thanks I learned enough python to complete an online course from Dr Chuck but I don't write enough code to remember how except for a simple task that is usually simpler to do manually than to remember how to code. http://www.dr-chuck.com/ Thanks to everyone else too. BTW I was trying to use a line like yours that used an output file that didn't exist and was getting an error. I assume that import os fixes that. -- https://mail.python.org/mailman/listinfo/python-list