Re: Subclassing int

2007-07-24 Thread Alex Popescu
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: >

Re: Subclassing int

2007-07-23 Thread G
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

Subclassing int

2007-07-23 Thread G
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

Re: Subclassing int

2007-07-23 Thread Steve Holden
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

Re: changing value of 'self' when subclassing int

2006-02-21 Thread David Coffin
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

Re: changing value of 'self' when subclassing int

2006-02-21 Thread Nick Craig-Wood
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

Re: changing value of 'self' when subclassing int

2006-02-21 Thread Fuzzyman
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

Re: changing value of 'self' when subclassing int

2006-02-20 Thread Alex Martelli
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

changing value of 'self' when subclassing int

2006-02-20 Thread David Coffin
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