Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28262
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Subject | Re: [2.5.1] Read each line from txt file, replace, and save? |
| Date | 2012-09-02 12:02 +0100 |
| References | <uec64893qomnns4ih36319m47bkkpqr488@4ax.com> <nid648l7k80oli3t84okl598s5fqkgascn@4ax.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.77.1346583562.27098.python-list@python.org> (permalink) |
On 02/09/2012 11:36, Gilles wrote:
> On Sun, 02 Sep 2012 12:19:02 +0200, Gilles <nospam@nospam.com> wrote:
> (snip)
>
> Found it:
>
> #rewrite lines to new file
> output = open('output.txt','w')
>
> for line in textlines:
> #edit each line
> line = "just a test"
> output.write("%s" % line)
>
> output.close()
>
IMHO better practice to use the with statement. See
http://docs.python.org/reference/compound_stmts.html#the-with-statement
--
Cheers.
Mark Lawrence.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[2.5.1] Read each line from txt file, replace, and save? Gilles <nospam@nospam.com> - 2012-09-02 12:19 +0200
Re: [2.5.1] Read each line from txt file, replace, and save? Gilles <nospam@nospam.com> - 2012-09-02 12:36 +0200
Re: [2.5.1] Read each line from txt file, replace, and save? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-09-02 12:02 +0100
Re: [2.5.1] Read each line from txt file, replace, and save? Terry Reedy <tjreedy@udel.edu> - 2012-09-02 14:04 -0400
Re: [2.5.1] Read each line from txt file, replace, and save? Gilles <nospam@nospam.com> - 2012-09-05 14:52 +0200
csiph-web