Re: trouble understanding inheritance...

2006-08-27 Thread Bruno Desthuilliers
Steven D'Aprano a écrit : (snip) > class BaseClass(): > def foo(self): > return "foo" > > class Foo(BaseClass): > def foo(self): > return self.__class__.foo() # call the parent class method Err... May I suggest that you re-read the Fine Manual ? -- http://mail.python.org/

Re: trouble understanding inheritance...

2006-08-17 Thread enigmadude
If what you're trying to do is have more control over the type of object that is instantiated, then you could use a function that decides what class to use based upon the arguments supplied to the function, where it then instantiates an object from the chosen class, then returns the object. The __i

Re: trouble understanding inheritance...

2006-08-17 Thread Ant
Try running the following example - it should help clear up what is going on: class Base: def __init__(self): print "Initializing base" def shouldBeImplemented(self): raise NotImplementedError def hasDefaultImplementation(self): print "Wey Hey!" class A(Base):

Re: trouble understanding inheritance...

2006-08-17 Thread Jason
KraftDiner wrote: > c = [a, b] > for c in [a,b]: >c.getName() > > but when does baseClass ever get used? > Why did i even have to define it? > One reason for using base classes are for logical reasons. Oranges and Apples are different, but they are both fruits. Python has both unicode string

Re: trouble understanding inheritance...

2006-08-17 Thread Steven D'Aprano
On Wed, 16 Aug 2006 12:53:12 -0700, KraftDiner wrote: >> > Well how does one select which class baseClass really is when you >> > contruct the object? >> > What am I missing? >> > >> > a = typeA() >> > b = typeB() >> > c = baseClass(a) >> >> a = typeA() >> b = typeB() >> >> You're done. Stop there

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Simon Brunning wrote: > On 16 Aug 2006 12:53:12 -0700, KraftDiner <[EMAIL PROTECTED]> wrote: > > I can see that this might work... > > c = [a, b] > > for c in [a,b]: > >c.getName() > > > > but when does baseClass ever get used? > > Why did i even have to define it? > > Well, quite. > I agree..

Re: trouble understanding inheritance...

2006-08-16 Thread Simon Brunning
On 16 Aug 2006 12:53:12 -0700, KraftDiner <[EMAIL PROTECTED]> wrote: > I can see that this might work... > c = [a, b] > for c in [a,b]: >c.getName() > > but when does baseClass ever get used? > Why did i even have to define it? Well, quite. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.b

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Simon Forman wrote: > KraftDiner wrote: > > Fredrik Lundh wrote: > > > KraftDiner wrote: > > > > > > > This is not working the way I think it should > > > > it would appear that fromfile and getName are calling the baseClass > > > > methods which are > > > > simple passes What have I done

Re: trouble understanding inheritance...

2006-08-16 Thread Simon Forman
KraftDiner wrote: > Fredrik Lundh wrote: > > KraftDiner wrote: > > > > > This is not working the way I think it should > > > it would appear that fromfile and getName are calling the baseClass > > > methods which are > > > simple passes What have I done wrong? > > > > > > class baseClass: >

Re: trouble understanding inheritance...

2006-08-16 Thread KraftDiner
Fredrik Lundh wrote: > KraftDiner wrote: > > > This is not working the way I think it should > > it would appear that fromfile and getName are calling the baseClass > > methods which are > > simple passes What have I done wrong? > > > > class baseClass: > > def __init__(self, type): >

Re: trouble understanding inheritance...

2006-08-16 Thread Fredrik Lundh
KraftDiner wrote: > This is not working the way I think it should > it would appear that fromfile and getName are calling the baseClass > methods which are > simple passes What have I done wrong? > > class baseClass: > def __init__(self, type): > if type == 'A': >

trouble understanding inheritance...

2006-08-16 Thread KraftDiner
This is not working the way I think it should it would appear that fromfile and getName are calling the baseClass methods which are simple passes What have I done wrong? class baseClass: def __init__(self, type): if type == 'A': self = typeA(