By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,985 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,985 IT Pros & Developers. It's quick & easy.

__new__ and dynamic inheriting

P: n/a
Hi all.
It's easier if I show an example first.

Say I have

class A(object):
def speak(self): print 'A!'

class B(object):
def speak(self): print 'B!'

I also have a factory function like this.

def foo(kind,*args,**kwds):
if kind=='a': return A(*args,**kwds)
else: return B(*args,**kwds)

I need foo to be a class, so that I could inherit from it and still use it
as a factory, so that I can do:


class Final(Foo):
def __init__(self,kind,*args,**kwds):

Can I do it? How ?
If it is possible, I'm pretty sure it involves using __new__ on Foo, but I
can't figure out how to make it works.

Any help is appreciated.

Thank you,

Riccardo Galli
Sideralis Programs
Jul 19 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.