decimal and trunkating

Peter Hansen peter at engcorp.com
Fri Jun 3 13:31:09 CEST 2005


chris wrote:
> I'm new to Python ... and I've used decimal._round() as above. What's the
> deal with using underscore methods? (A link will do if that'll save you some
> typing).

Generally the underscore methods provide *internal* functionality that 
might be used by other, more externally accessible (i.e. documented!) 
methods in the object.  While as I've said I'm no expert in Decimal and 
can't say how _round() is intended to be used, it is not documented (as 
far as I can see) and certainly therefore follows this way of thinking 
about underscore methods.  Several of us have found at least one 
suitable alternative (i.e. quantize()) that don't rely on underscore 
methods.

(Think of the underscore as being a non-binding convention that says 
"don't use this externally if possible, as it doesn't form part of the 
contract guaranteed by this object... it may be removed in the future, 
may not work exactly as you wish, may have side effects that aren't 
documented or haven't been analyzed fully when used externally, etc.")

-Peter



More information about the Python-list mailing list