Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #107681

Re: Python path and append

Path csiph.com!feeder.erje.net!1.eu.feeder.erje.net!news2.arglkargh.de!news.karotte.org!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael <bigbadmick2000@hotmail.com>
Newsgroups comp.lang.python
Subject Re: Python path and append
Date Tue, 26 Apr 2016 19:16:56 +0100
Lines 26
Message-ID <mailman.123.1461694693.32212.python-list@python.org> (permalink)
References <DUB116-W85F8F15123A15716395CA7CA630@phx.gbl>
Mime-Version 1.0
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de sf+UBX4sZoOIz7YIxBIPOgqUYcJQ8VdCjaZ0Lqen4ZlA==
Return-Path <bigbadmick2000@hotmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.026
X-Spam-Evidence '*H*': 0.95; '*S*': 0.00; 'subject:Python': 0.05; 'append': 0.07; "'w')": 0.09; 'lines:': 0.09; 'file,': 0.15; "'r')": 0.16; 'f.read()': 0.16; 'helps!': 0.16; 'need:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'to:name:python- list@python.org': 0.20; 'if,': 0.29; 'code:': 0.29; 'code': 0.30; 'another': 0.32; 'file': 0.34; 'text': 0.35; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'end': 0.39; 'to:addr:python.org': 0.40; 'space': 0.40; 'hope': 0.61; 'entire': 0.61; 'wish': 0.71; 'asterisk': 0.84; 'email addr:hotmail.com': 0.89; 'hand,': 0.97
X-TMN [593pVeoxWgv+CW+mXShr32kLHnWUXf4W]
X-Originating-Email [bigbadmick2000@hotmail.com]
Importance Normal
X-OriginalArrivalTime 26 Apr 2016 18:16:56.0397 (UTC) FILETIME=[D10C6FD0:01D19FE7]
X-Mailman-Approved-At Tue, 26 Apr 2016 14:18:12 -0400
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <DUB116-W85F8F15123A15716395CA7CA630@phx.gbl>
Xref csiph.com comp.lang.python:107681

Show key headers only | View raw


If you want to read an entire file, append a space and asterisk and write it to another file, this is the code you need:

infile = open('win.txt', 'r')
text = f.read()
infile.close()
text += " *"
outfile = open('outfile.txt', 'w')
outfile.write(text)
outfile.close()

If, on the other hand, you wish to read a file and append a space and asterisk TO THE END OF EVERY LINE, you require the following code:
infile = open('win.txt', 'r')
lines = infile.readlines()
infile.close()
outfile = open('outfile.txt', 'w')
for line in lines:
    line = line.strip() + " *\n"
    outfile.write(line)
outfile.close()

Hope that helps!

BigBadMick
bigbadmick2000@hotmail.com 		 	   		  

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Python path and append Michael <bigbadmick2000@hotmail.com> - 2016-04-26 19:16 +0100
  Re: Python path and append Seymore4Head <Seymore4Head@Hotmail.invalid> - 2016-04-26 22:57 -0400

csiph-web