(original) (raw)
RE: \[Python-Dev\] Decimal - context manipulation\[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.