On May 19, 12:04 am, Erik Max Francis <m...@alcyone.com> wrote:
> Adam W. wrote:
> > I thought I knew how classes worked, but this code sample is making my
> > second guess myself:
>
> > import threading
>
> > class nThread(threading.Thread):
> >     def __init__(self):
> >         threading.Thread.__init__(self)
>
> >     def run(self,args):
> >         print self.name
> >         print self.args
>
> > pants = nThread(args=('fruit'),name='charlie')
> > pants.start()
>
> > Traceback (most recent call last):
> >   File "C:\Users\Adam\Desktop\PyTiVo\task_master.py", line 13, in
> > <module>
> >     pants = nThread(args=('fruit'),name='charlie')
> > TypeError: __init__() got an unexpected keyword argument 'args'
>
> > Shouldn't __init__ still handle these (as per
> >http://docs.python.org/library/threading.html#thread-objects), even
> > if its subclassed?  I thought this was the whole idea of inheritance
> > and overdriving.
>
> You've overridden the __init__ method to _not_ take any arguments, and
> explicitly call its parent constructor not passing anything.  So it
> shouldn't be a wonder that it won't accept any arguments.
>
> If you don't intend to override the constructor in the parent class,
> simply don't define it.

Hummm, so lets say I wanted it pass all the variables to the parent
constructor, how would I do that?  I wouldn't have to list every
variable it could possible receive would I?

This is like the opposite behavior I remember.  When working with PyQt
GUI classes, I swear I just sub classed the few things I wanted to
change, and everything else would refer back to the parent...

What I really just want to do is pass run() some args, which is what I
assumed the default __init__'s args was for, but I give it args
without sub classing __init__ and it has no idea what to do with
them.  I subclass __init__ to take args, and I break everything else?
Is this really how this is supposed to work?
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to