G <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> --=_Part_187401_13883248.1185238999144
> Hi,
>
> I am trying to subclass int to allow a constructor to accept None.
> I am
> trying the following
>
> class INT(int):
> def __init__(self, x):
> if x is None:
>
Thanks a lot Matt and Steve. I replaced __int__ with __new__ and it worked
On 7/23/07, Matt McCredie <[EMAIL PROTECTED]> wrote:
Do you guys know why the if statement is not evaluated?
For immutable types __new__ is called before __init__. There are some
details here: http://docs.python.org/r
Hi,
I am trying to subclass int to allow a constructor to accept None. I am
trying the following
class INT(int):
def __init__(self, x):
if x is None:
return None
else:
int.__init__(x)
b = INT(x=None)
When i run the previous code i get the following er
G wrote:
> Hi,
>
> I am trying to subclass int to allow a constructor to accept None. I
> am trying the following
>
> class INT(int):
> def __init__(self, x):
> if x is None:
> return None
> else:
> int.__init__(x)
>
> b = INT(x=None)
>
> When i
Thanks for all the help.
> On 20 Feb 2006, at 17:34, Alex Martelli wrote:
>
> ...integers are immutable, like all other numbers in Python: there
> is NO
> way to "change the value of the integer itself".
So, on learning that I could subclass the number types, I didn't even
consider the fact t
David Coffin <[EMAIL PROTECTED]> wrote:
> I'd like to subclass int to support list access, treating the integer
> as if it were a list of bits.
> Assigning bits to particular indices involves changing the value of
> the integer itself, but changing 'self' obviously just alters the
> valu
David Coffin wrote:
> I'd like to subclass int to support list access, treating the integer
> as if it were a list of bits.
> Assigning bits to particular indices involves changing the value of
> the integer itself, but changing 'self' obviously just alters the
> value of that local variable.
> Is
David Coffin <[EMAIL PROTECTED]> wrote:
> I'd like to subclass int to support list access, treating the integer
> as if it were a list of bits.
Fine, but:
> Assigning bits to particular indices involves changing the value of
> the integer itself, but changing 'self' obviously just alters the
e way for me to change the value of the BitSequence
object itself? I've also tried wrapping and delegating using
__getattr__, but I couldn't figure out how to handle in-place methods.
Thanks for your help,
David Coffin
class BitSequence(int):
"""An integer emula