Michael Chermside wrote:

#-         I think that we'd do even better to ommit the second
#- use. People who
#- really want to convert floats exactly can easily write
#- "Decimal(1.1, 60)". But
#- hardly anyone wants to convert floats exactly, while lots of
#- newbies would
#- forget to include the second parameter. I'd say just make
#- Decimal(someFloat)
#- raise a TypeError with a helpful message about how you need
#- that second
#- parameter when using floats.

I take this in consideration in another response.

#- Really, that's all I came up with. This is great, and I'm
#- looking forward to
#- using it. I would, though, be interested in a couple more
#- syntax-related
#- details:
#-     (a) What's the syntax for changing the context? I'd
#- think we'd want
#- a "pushDecimalContext()" and "popDecimalContext()" sort of
#- approach, since most
#- well-behaved routines will want to restore their caller's context.

You can save a copy of the context in a variable and then restore it. No stack.

#- context? I don't
#- have any use cases, but it would seem peculiar not to provide it.

You do it to save it in a variable.

For example:

>>> from Decimal import *
>>> import copy
>>> c = getcontext()
>>> cc = copy.copy(c)
>>> d = Decimal(5.065253542)
>>> d
Decimal( (0, (5, 0, 6, 5, 2, 5, 3, 5, 4, 2), -9) )
>>> d + 1     # it will be rounded down
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )
>>> c.set_rounding('up')   # returns the old rounding
'half_even'
>>> d + 1     # it will be rounded up
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 5), -8L) )
>>> setcontext(cc)
>>> d + 1
Decimal( (0, (6, 0, 6, 5, 2, 5, 3, 5, 4), -8L) )

One question: This kind of stuff, should be in the final documentation? And in the final PEP?

#-     (c) Given a Decimal object, is there a straightforward
#- way to determine its
#- coefficient and exponent? Methods named .precision() and
#- .exponent() might do
#- the trick.

No. I think it's a good idea.

.       Facundo

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .