python assignment

Ben Finney bignose-hates-spam at and-zip-does-too.com.au
Wed Jul 23 02:36:04 EDT 2003


On 22 Jul 2003 17:59:08 -0700, dan wrote:
> What I need is an exact and unambiguous algorithm for determining when
> an assignment will change the id of the variable

As I understand it, this is specific to the implementation of each type.
The only sensible way to code is as if the identity of an object, on
assignment, were completely unpredictable.

The examples you gave showed that integers share identity with other
integers of the same value, while floats do not.  This demonstrates why
it's a poor idea to expect assignment to behave a particular way w.r.t.
object identity: an alternative implementation may be more efficient,
yet have a different relationship with identity.

If you write your code so that it expects a particular identity
behaviour w.r.t. assignment, that prevents future implementation changes
without breaking your code.

-- 
 \        "Good judgement comes from experience. Experience comes from |
  `\                           bad judgement."  -- Frederick P. Brooks |
_o__)                                                                  |
http://bignose.squidly.org/ 9CFE12B0 791A4267 887F520C B7AC2E51 BD41714B




More information about the Python-list mailing list