Python path and append

Michael bigbadmick2000 at hotmail.com
Tue Apr 26 14:16:56 EDT 2016


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 at hotmail.com 		 	   		  


More information about the Python-list mailing list