[Tutor] python precision output?

Andre Walker-Loud walksloud at gmail.com
Thu Dec 6 23:05:08 CET 2007

Hi there,

I am using python to do some scripting.  In particular, I am using it  
to run some jobs which require precision inputs.  I do this by having  
python write an input file, which I then feed to some other program.

The problem I am having is getting python to write number into this  
input file, keeping 16 digits of precision.  I have played around  
interactively, and see that python default prints 17 digits of  
precision to the screen, but when I use a replace command to write  
into the input file, it only prints 12 digits of precision.  The  
relevant snipit of my script is

value = float( int(ai) * 6 * math.pi / (int(L)*int(T))
replace = {'VALUE':str(value)}
ini_file = open('generic_ini').read()
f.write(ini_file % replace)

where, "ai", "L" and "T" are process dependent numbers defined in my  
script, and the output "my_input.xml", is just an xml file I later  
feed to another program, and this is why I replace 'VALUE' with a  

To reiterate, I need str(value) to be written to my file with 16  
digits of precision...???


More information about the Tutor mailing list