writing to a file

Szabolcs Nagy nszabolcs at gmail.com
Wed May 30 05:57:35 EDT 2007


montyphy... at gmail.com wrote:
> as i understand there are two ways to write data to a file: using
> f.write("foo") and print >>f, "foo".
well print will add a '\n' or ' ' if you use ',' after it

> what i want to know is which one is faster (if there is any difference
there shouldn't be any noticable difference

> in speed) since i'm working with very large files. of course, if there
> is any other way to write data to a file, i'd love to hear about it
other ways:
os.system('cat file1 >> file2')
or subprocess.Popen
or print but sys.stdout = f
or ctypes + printf/fputs/..

and probably there are other obscure ways, but the intended way is
obviously f.write

nsz




More information about the Python-list mailing list