Vicent wrote:
Hello. The problem is: there is no way that I know of to add fundamental types to Python. Also realize that variables are dynamically typed - so any assignment can create a variable of a new type. That is why a = 0 results in an int. So one must resort, as others have mentioned, to classes. Framework (untested): class Bit: _value = 0 # default def __init__(self, value): self._value = int(bool(value)) def getvalue(self): return self._x def setvalue(self, value): self._x = int(bool(value)) value = property(getvalue, setvalue) def __add__(self, other): # causes + to act as or self._value |= other def __mul__(self, other): # causes * to act as and self._value &= other b = Bit(1) b.value # returns 1 b.value = 0 b.value # returns 0 b.value + 1 # sets value to 1 b.value * 0 # sets value to 0 --
Bob Gailer Chapel Hill NC 919-636-4239 |
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor