Formatted numerical output
kent3737 at yahoo.com
Sun Nov 28 04:43:29 CET 2004
> How do I output formatted numerical data to an external (text) file. At
> a minimum I want to specify the number of decimal places to print.
> Ideally I'd like the type of control the fortran FORMAT statement
> offers. I'm sure this is easy, but I can't seem to find the answer!
Use string formatting operations
> I want an output file to look like this:
> 0.1 0.8575
> 0.2 12.0900
> 0.4 345.0000
> 0.5 9.0002
s = "%3.1f %8.4f\n" % (x, y)
More information about the Python-list