[Python-Dev] Decimal - context manipulation

Batista, Facundo FBatista at uniFON.com.ar
Wed Apr 21 11:55:00 EDT 2004


[Paul Moore]

#- One thing I couldn't find an obvious way of doing with Decimal is to
#- obtain a copy of the current context, with a different (say)
#- precision. The Context constructor defaults from 
#- DefaultContext rather
#- than from the current context, and I can't see a way of modifying the
#- precision of a Context object (is the "prec" attribute intended to be
#- publicly writeable?) I assume that copy.copy works to copy a context,
#- although maybe an explicit copy method would be useful?

>>> from Decimal import *
>>> actual_context = getcontext()
>>> copied_context = copy.copy(actual_context)
>>> copied_context.prec = 5
>>> +Decimal('123456789')
Decimal( (0, (1, 2, 3, 4, 5, 6, 7, 8, 9), 0) )
>>> actual_context.prec = 5
>>> +Decimal('123456789')
Decimal( (0, (1, 2, 3, 4, 6), 4L) )

Note the + in front of the creation of Decimal: that implies an operation
and that's why the context get involved.

Regarding a copy() method in Context class, don't know. It's really easy to
implement, but don't know if the standard preference is to get a copy method
inside each data type (I'm confused about dictionaries having a copy method
and lists, for example, not having it).

.	Facundo





. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . .
ADVERTENCIA  

La información contenida en este mensaje y cualquier archivo anexo al mismo,
son para uso exclusivo del destinatario y pueden contener información
confidencial o propietaria, cuya divulgación es sancionada por la ley. 

Si Ud. No es uno de los destinatarios consignados o la persona responsable
de hacer llegar este mensaje a los destinatarios consignados, no está
autorizado a divulgar, copiar, distribuir o retener información (o parte de
ella) contenida en este mensaje. Por favor notifíquenos respondiendo al
remitente, borre el mensaje original y borre las copias (impresas o grabadas
en cualquier medio magnético) que pueda haber realizado del mismo. 

Todas las opiniones contenidas en este mail son propias del autor del
mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones
Personales S.A. o alguna empresa asociada. 

Los mensajes electrónicos pueden ser alterados, motivo por el cual
Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación
cualquiera sea el resultante de este mensaje. 

Muchas Gracias.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-dev/attachments/20040421/025b75b3/attachment.html


More information about the Python-Dev mailing list