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


Groups > comp.lang.python > #107681 > unrolled thread

Re: Python path and append

Started byMichael <bigbadmick2000@hotmail.com>
First post2016-04-26 19:16 +0100
Last post2016-04-26 22:57 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#107681 — Re: Python path and append

FromMichael <bigbadmick2000@hotmail.com>
Date2016-04-26 19:16 +0100
SubjectRe: Python path and append
Message-ID<mailman.123.1461694693.32212.python-list@python.org>
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 		 	   		  

[toc] | [next] | [standalone]


#107701

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2016-04-26 22:57 -0400
Message-ID<vja0ib9qb2sdmk0mfj0ilna1edtl1vqhes@4ax.com>
In reply to#107681
On Tue, 26 Apr 2016 19:16:56 +0100, Michael
<bigbadmick2000@hotmail.com> wrote:

>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 		 	   		  

I will have a look at this.
Thanks

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web