<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Wayne,<div><br></div><div>Yes - that helps. &nbsp;I missed the correct combination of parentheses.</div><div><br></div><div>Now I am trying to improve my aesthetics, as Evert suggested earlier</div><div><br></div><div><blockquote type="cite"><div>Personally, I would print this as 7.63e-03 +- 0.83e-03, which shows the precision a bit better. But that's just a matter of aesthetics, and would make things even more complicated (then again, since you are printing numbers and formatting them, you are concerned about aesthetics).</div></blockquote><br></div><div>I agree with him here, and would like to match this style. &nbsp;I have been trying to figure out if you can specify the "mantissa" and exponent in scientific notation, by reading in the string.format section of python, but have been unsuccessful. &nbsp;Is there an easy way to do this? &nbsp;To be precise, I now have</div><div><br></div><div>&gt; a =&nbsp;0.0762921383941;&nbsp;ea = 0.000830132912068</div><div>&gt;&nbsp;p = int(("%.1e" % (a / ea)).split('e')[-1])&nbsp;</div><div>&gt; print(('%.' + str(int(2+p)) +'e +- %.1e') % (a, ea))</div><div>7.629e-02 +- 8.3e-04</div><div><br></div><div>and instead I would like this to print</div><div><br></div><div>7.629e-02 +- 0.083e-02</div><div><br></div><div>I could imagine writing a little function that does all this, but am hoping there is a quick (and dirty) way to just force the scientific notation to into this format - I guess by forcing the power of the exponent.</div><div><br></div><div><br></div><div>Thanks,</div><div><br></div><div>Andre</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br><div><div>On Oct 5, 2010, at 6:39 PM, Wayne Werner wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div class="gmail_quote">On Tue, Oct 5, 2010 at 7:51 PM, Andre' Walker-Loud <span dir="ltr">&lt;<a href="mailto:walksloud@gmail.com">walksloud@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi Alan,<br>
<br>
The point I can not get to work is<br>
<div class="im"><br>
&gt; fmt = "%.%de + %.1e" % n &nbsp;else:<br>
<br>
</div>when I try this, I get (python 2.6.5, OS X 10.6)<br>
<br>
&gt; n = 3; fmt = "%.%de + %.1e" % n; fmt<br>
'%de + 3.0e+00'<br>
<br>
But something like the "%.%de " %n is exactly what I am looking for - if I could get it to work.<br></blockquote><div><br></div><div><br></div><div><div>a = 0.00762921383941</div><div>ea = 0.000830132912068</div>

<div><br></div><div><br></div><div>p = int(("%.1e" % (a / ea)).split('e')[-1]) # grab the power in the scientific n</div><div>otation (is there a better way?)</div><div>if p &gt;= 0:</div><div>&nbsp;&nbsp; &nbsp;print(('%.' + str(int(2+p)) +'e +- %.1e') % (a, ea))</div>

<div>else:</div><div>&nbsp;&nbsp; &nbsp;print('%.2e +- %.1e' % (a, ea))</div><div>&nbsp;&nbsp; &nbsp;#(desired output): 7.63e-03 +- 8.3e-04</div></div><div><br></div><div><br></div><div>This works for me - I added some extra parenthesis because the original was giving me this error:</div>

<div><br></div><div><div>Traceback (most recent call last):</div><div>&nbsp;&nbsp;File "exponent.py", line 7, in &lt;module&gt;</div><div>&nbsp;&nbsp; &nbsp;print('%.' + str(int(2+p)) +'e +- %.1e' % (a, ea))</div><div>TypeError: not all arguments converted during string formatting</div>

</div><div><br></div><div>HTH,</div><div>Wayne</div><div><br></div></div>
</blockquote></div><br></div></body></html>