Path: csiph.com!weretis.net!feeder6.news.weretis.net!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!bloom-beacon.mit.edu!bloom-beacon.mit.edu!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Python path and append Date: Mon, 25 Apr 2016 21:26:34 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 39 Message-ID: References: <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> NNTP-Posting-Host: panix2.panix.com X-Trace: reader1.panix.com 1461619594 27356 166.84.1.2 (25 Apr 2016 21:26:34 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Mon, 25 Apr 2016 21:26:34 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:107630 In <27nshbp40p1llr231dqm31p754tvurkb8i@4ax.com> Seymore4Head writes: > On Tue, 19 Apr 2016 18:29:38 -0400, Seymore4Head > 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') -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"