Re: downcasting problem

2010-10-29 Thread Lawrence D'Oliveiro
In message , Nikola Skoric wrote: > I have a file full of lines which I parse into Line objects. I also > have two subclasses of Line, namely Individual and Family. Constructor > of both subclasses needs all Line objects in the file to be > constructed, so I cannot construct subclass objects in th

Re: downcasting problem

2010-10-26 Thread Hrvoje Niksic
John Nagle writes: > On 10/25/2010 7:38 AM, Tim Chase wrote: >> While a dirty hack for which I'd tend to smack anybody who used it...you >> *can* assign to instance.__class__ > >That's an implementation detail of CPython. May not work in > IronPython, Unladen Swallow, PyPy, or Shed Skin. > >

Re: downcasting problem

2010-10-25 Thread Tim Chase
On 10/25/2010 12:56 PM, John Nagle wrote: On 10/25/2010 7:38 AM, Tim Chase wrote: While a dirty hack for which I'd tend to smack anybody who used it...you *can* assign to instance.__class__ That's an implementation detail of CPython. May not work in IronPython, Unladen Swallow, PyPy, or

Re: downcasting problem

2010-10-25 Thread Diez B. Roggisch
Nikola Skoric writes: > Hi everybody, > > I need to downcast an object, and I've read repeatedly that if you > need to downcast, you did something wrong in the design phase. So, > instead of asking how do you downcast in python, let me explain my > situation. > > I have a 2-pass parser. 1st pass

Re: downcasting problem

2010-10-25 Thread Emmanuel Surleau
> Hi everybody, > > I need to downcast an object, and I've read repeatedly that if you > need to downcast, you did something wrong in the design phase. So, > instead of asking how do you downcast in python, let me explain my > situation. > > I have a 2-pass parser. 1st pass ends up with a bunch o

Re: downcasting problem

2010-10-25 Thread John Nagle
On 10/25/2010 7:38 AM, Tim Chase wrote: While a dirty hack for which I'd tend to smack anybody who used it...you *can* assign to instance.__class__ That's an implementation detail of CPython. May not work in IronPython, Unladen Swallow, PyPy, or Shed Skin. (An implementation with a JIT h

Re: downcasting problem

2010-10-25 Thread Nikola Skoric
Dana Mon, 25 Oct 2010 09:38:42 -0500, Tim Chase kaze: > While a dirty hack for which I'd tend to smack anybody who used > it...you *can* assign to instance.__class__ Wow! Python never stops to amaze me. > If it breaks you get to keep all the parts :) Yes, I can see great potential for shit hi

Re: downcasting problem

2010-10-25 Thread Tim Chase
While a dirty hack for which I'd tend to smack anybody who used it...you *can* assign to instance.__class__ >>> class A: ... def __init__(self, name): ... self.name = name ... def __str__(self): return self.name ... >>> class B(A): ... def foo(self): print "I'm B: %r" % s

downcasting problem

2010-10-25 Thread Nikola Skoric
Hi everybody, I need to downcast an object, and I've read repeatedly that if you need to downcast, you did something wrong in the design phase. So, instead of asking how do you downcast in python, let me explain my situation. I have a 2-pass parser. 1st pass ends up with a bunch of superclass obj