Sir Galahad the chaste <[EMAIL PROTECTED]> writes: > Hi, > > [EMAIL PROTECTED] wrote: >> How should I: Open a Text file, read from it, modify it, print to >> another .txt? >> For instance: Read a string, sort it, write the sorted string. > > What do you mean by "sorting"? If you want to sort the lines contained > in a file, you could do something like this. > > $ cat in.txt > foo > bar > baz > ham > spam > $ cat process.py > #!/usr/bin/env python > lines = open("in.txt").readlines()
Some people consider it bad style to leave opened files lieing around, so this shold be: f = open("in.txt") lines = f.readlines() f.close() > lines.sort() > out = open("out.txt", "w") > for line in lines: > out.write(line) Those two should be out.writelines(lines) > out.close() <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list