Using equals operator without changing reference pointer

mark.seagoe at mark.seagoe at
Fri Jan 30 16:31:45 CET 2009

On Jan 29, 8:03 pm, Terry Reedy <tjre... at> wrote:
> Erik Max Francis wrote:
> > mark.sea... at wrote:
> >> Is there a way to lock down myInst so that it still refers to the
> >> original object, and is there some special member that will allow me
> >> to override the equals operator in this case?  Or is that simply
> >> blasphemous against everything Python holds sacred?  Certainly there
> >> is some keyword that I don't know about.
> > No.  The assignment operator with a bare name on the left hand side is
> > not overridable.
> So that 'name = ob' *always* binds name to ob.  That is one thing one
> can depend on when reading Python code.
> > You can override attribute access, however, with
> > .__getattr__/.__getattribute__.
> I presume that you have over-riden __setitem__ in addition to
> __getitem__ so that myOb[0] = 1 sets the bit. You could add a branch to
> __setitem__ (or define __setslice__ in 2.x) so that myOb[:] = 0x55 does
> just what you want it to -- set all bits.  Being able to get/set
> contiguous bits might be something you want anyway.
> tjr
> PS. When asking about internal details, specify version of interest, as
> there have been minor changes.

OK.  Thanks for your advice.

More information about the Python-list mailing list