471,336 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

initializing cooperative method

Hi,

I'm writing a bunch of abstract classes and I'd like to delegate the
arguments of the concrete class the to abstract one. I was surprised
to see that the print statement in the abstract class isn't executed.
But moreover, I'd like to find out an idiom that allows one to
delegate arguments in the inherited class. Any ideas?

Thanks,

-jelle

class Abstract(object):
def __init__(self, a='a', b='b'):
self.a, self.b = a, b
print a, b

class Concrete(Abstract):
def __init__(self, a='AAA', b='BBB'):
super(Abstract, self).__init__( a=a, b=b )
print a, b

c = Concrete(a=1)
>>c = Concrete(a=1)
1 BBB

Sep 6 '07 #1
4 883
On Thu, 06 Sep 2007 16:12:11 +0000, jelle wrote:
Hi,

I'm writing a bunch of abstract classes and I'd like to delegate the
arguments of the concrete class the to abstract one. I was surprised to
see that the print statement in the abstract class isn't executed. But
moreover, I'd like to find out an idiom that allows one to delegate
arguments in the inherited class. Any ideas?
Change the call to super() in Concrete from:

super(Abstract, self).__init__(a, b)

to

super(Concrete, self).__init__(a, b)

--
Steven.

Sep 6 '07 #2
Ai, calling super(Abstract) is just getting object, sure...

However, I'm still curious to know if there's a good idiom for
repeating the argument in __init__ for the super(Concrete,
self).__init__ ?

Thanks,

-jelle

Sep 6 '07 #3
Ai, calling super(Abstract) is just getting object, sure...

However, I'm still curious to know if there's a good idiom for
repeating the argument in __init__ for the super(Concrete,
self).__init__ ?

Thanks,

-jelle

Sep 6 '07 #4
On Sep 6, 11:18 am, jelle <jelleferi...@gmail.comwrote:
Ai, calling super(Abstract) is just getting object, sure...

However, I'm still curious to know if there's a good idiom for
repeating the argument in __init__ for the super(Concrete,
self).__init__ ?
If you don't know what the arguments are, you can use *args and
**kwargs.

class Concrete(Abstract):
def __init__(self, *args, **kwargs):
super(Concrete, self).__init__(*args, **kwargs)
Sep 6 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

50 posts views Thread by Dan Perl | last post: by
reply views Thread by Dan Perl | last post: by
14 posts views Thread by Axel Straschil | last post: by
2 posts views Thread by Dave | last post: by
3 posts views Thread by Aengys | last post: by
17 posts views Thread by Calle Pettersson | last post: by
8 posts views Thread by John | last post: by
14 posts views Thread by Akihiro KAYAMA | last post: by
3 posts views Thread by Reckoner | last post: by
13 posts views Thread by WaterWalk | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.