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/
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
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):
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
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
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..
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
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
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:
>
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):
>
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':
>
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(
12 matches
Mail list logo