Writing to a file

jyoung79 at kc.rr.com jyoung79 at kc.rr.com
Fri Mar 25 11:07:19 EDT 2011


Just curious how others view the 2 examples below for creating and 
writing to a file in Python (in OS X).  Is one way better than the other?  
If it was a large amount of text, would the 'os.system' call be a bad 
way to do it?

Thanks.

Jay


>>> f = open('~/Desktop/test.txt', 'w')
>>> f.write('testing 1... 2... 3...')
>>> f.close()
>>> 
>>> 
>>> import os
>>> os.system('echo "Testing a... b... c..." > "~/Desktop/test2.txt"')
0
>>> 




More information about the Python-list mailing list