467,859 Members | 1,383 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,859 developers. It's quick & easy.

Formatted numerical output

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!

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

etc.

Thanks,

Mark
Jul 18 '05 #1
  • viewed: 1606
Share:
2 Replies
Mark wrote:
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
http://docs.python.org/lib/typesseq-strings.html

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


Something like

s = "%3.1f %8.4f\n" % (x, y)
out.write(s)
Kent
Jul 18 '05 #2
Kent Johnson wrote:
Mark wrote:
How do I output formatted numerical data to an external (text) file.


Use string formatting operations
http://docs.python.org/lib/typesseq-strings.html


Great stuff. Thanks.
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Craig Thomson | last post: by
10 posts views Thread by 2mc | last post: by
8 posts views Thread by Matthew Thorley | last post: by
4 posts views Thread by Joe C | last post: by
2 posts views Thread by Steven T. Hatton | last post: by
3 posts views Thread by Craig Petrie | last post: by
6 posts views Thread by Jojo | last post: by
4 posts views Thread by keith | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.