Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107681
| From | Michael <bigbadmick2000@hotmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Python path and append |
| Date | 2016-04-26 19:16 +0100 |
| Message-ID | <mailman.123.1461694693.32212.python-list@python.org> (permalink) |
| References | <DUB116-W85F8F15123A15716395CA7CA630@phx.gbl> |
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 | Next — Next in thread | Find similar | Unroll 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