473,505 Members | 13,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
2 1766
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
2098
by: Craig Thomson | last post by:
Do people generally try and output nicely formatted html from their scripts? I have been trying to, with variable indenting for tables etc. It makes it easier to see the html and perhaps debug...
10
3227
by: 2mc | last post by:
I'm new to Python and to Numerical Python. I have a program written in another program that used arrays extensively. I'm trying to convert to Python. Assume an array in Numerical Python, the...
8
5202
by: Matthew Thorley | last post by:
Greetings, perhaps someone can explain this. I get to different styles of formatting for xmla and xmlb when I do the following: from elementtree import ElementTree as et xmla =...
4
3554
by: Joe C | last post by:
I've written a console application and would like to isolate all screen output so that it will be easier to migrate the code to a GUI-type platform without modification to the base code. As a...
6
2186
by: Jason Heyes | last post by:
I am starting to worry about the performance of formatted read/write operations on data-redundant objects in my program.What can I do to improve this performance should it become an issue? ...
2
3492
by: Steven T. Hatton | last post by:
I'm still not completely sure what's going on with C++ I/O regarding the extractors and inserters. The following document seems a bit inconsistent:...
3
3354
by: Craig Petrie | last post by:
Hi, I have a large table in Word 2003 that has formatted text in the cells and wish to read and convert a cells formatted contents to html output via vb.net code. The formatting contains the...
6
3670
by: Jojo | last post by:
Hi all, I was wondering how I can perform formatted output with C++ strings. For example, suppose I have in plain C: sprintf(C_string, "%5.2f %6d"); How can I do such a thing with C++...
4
4640
by: keith | last post by:
I've been beating my head against this for a little while, so perhaps someone can help me out here? The code below should output exactly as follows (the hex data lines up in a fixed font): DATA...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.