1 |
Am Fri, 21 Sep 2012 02:31:45 -0400 |
2 |
schrieb Philip Webb <purslow@××××××××.net>: |
3 |
|
4 |
[...] |
5 |
> > 120919 Marc Joliet described how to set a level of precision: |
6 |
> |
7 |
> Thanks too, but that's not what I wanted: it's not for printing, |
8 |
> but simply to limit the display to eg 4 decimal places, not 16 ; |
9 |
> the calculations still wb as accurate, but the output easier to read. |
10 |
> Is that possible with Python ? -- ie a setting in ascript.py |
11 |
> to tell Python to display only the 1st 4 places in all output |
12 |
> without any further input from the user when doing the calculations; |
13 |
> presumably it wb a command s/he could enter when in interactive mode too. |
14 |
|
15 |
I couldn't find anything for regular python on the fly (except by using the |
16 |
"decimal" module, see |
17 |
http://docs.python.org/library/decimal.html#module-decimal), but I found out |
18 |
that IPython can do this by configuring its output formatters appropriately. To |
19 |
limit to 6 decimal places, my configuration would look like this: |
20 |
|
21 |
c.PlainTextFormatter.float_precision = '6' |
22 |
|
23 |
I would expect that all they do is implement hook functions that you could also |
24 |
put in place yourself, but to find out how to do it would require more digging |
25 |
than I have time for right now. Maybe you will find something first :) . |
26 |
|
27 |
HTH |
28 |
-- |
29 |
Marc Joliet |
30 |
-- |
31 |
"People who think they know everything really annoy those of us who know we |
32 |
don't" - Bjarne Stroustrup |