I've looked at tutorials on how to print to a file in Python, but I'm still have a problem. When I do:
x = a_function_that_spits_out_a_table
print x
The table looks great and is formatted properly. But when I do:
f=open(myfile,"w")
print >> f, x
I get a file with one line of text, without any line breaks. How do I print to a file exactly as how it appears when I use the print command?
print repr(x)look like? Allprint >> fobjdoes is write to a different file object instead ofsys.stdoutso the output is exactly the same for both methods.