Using equals operator without changing reference pointer

mark.seagoe at gmail.com mark.seagoe at gmail.com
Thu Jan 29 21:57:22 EST 2009


I know this may be asking too much of Python, but you never know
unless you ask...

So now having a class that can be treated like an int as far as math
upon the instance name, and can be treated as in HDL simulators,
allowing bitslice and bitselect ops, I was stoked.  Also reading back
the instance name returns the int, rather than text about the class
name and location in memory.  But... it would be wonderful if there
was a way to assign a value without using any .member notation... if
there were a way for me to specify that the reference would never
change.  For example:

>>> myInst = MyClass(0xAA)
>>> myInst
170
>>> myInst[0]  # <== MyClass can do bit selection
0
>>> myInst = 0x55   # <== gets reassigned
>>> myInst[0]    # <== this is where it would choke
1                     # <== this is the answer I would want

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.

Thanks!
Mark



More information about the Python-list mailing list