[Tutor] Fwd: Class Extend Help

Omer Jaggojaggo+Py at gmail.com
Sun Dec 28 23:49:53 CET 2008


Thx for help,
extreme lack of free time lately,
will look into it.

[Wouldn't've noticed myself that urlopen is not a class.]

On Tue, Dec 23, 2008 at 6:03 PM, Richard Lovely
<roadierich at googlemail.com>wrote:

> OK, going on Kent's post:
>
> from urllib import urlopen
>
> class fetch(object):
>    def __init__(self, *args):
>        self.response = urlopen(*args)
>        self.content = self.response.read()
>
>
> I forgot urlopen was a function.  It made sense in my head for it to
> be a class, instead of _returning_ a class.
>
> It's trying to call __init__ on a functionType instance, and it's
> getting confused.
>
> See http://dpaste.com/hold/101951/ for another example.  The error
> message is something cryptic, but between #python and I we think it's
> something to do with calling type().
> ---
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>
>
>
> 2008/12/23 Kent Johnson <kent37 at tds.net>:
> > On Tue, Dec 23, 2008 at 9:31 AM, Omer <Jaggojaggo+Py at gmail.com<Jaggojaggo%2BPy at gmail.com>>
> wrote:
> >
> >>>>> from urllib import urlopen
> >>>>> class fetch(urlopen):
> >> ...     def __init__(self,*args):
> >> ...         urlopen.__init__(self, *args)
> >> ...         self.content = self.read()
> >> ...
> >>
> >> Traceback (most recent call last):
> >>   File "<interactive input>", line 1, in <module>
> >> TypeError: Error when calling the metaclass bases
> >>     function() argument 1 must be code, not str
> >>
> >> Anybody, any idea what's up with that?
> >
> > That's pretty obscure, not sure why you get exactly that error!
> >
> > Anyway the code should be
> > class fetch(object):
> >
> > urlopen is a function, not a class, so it can't be a base class of
> > fetch. There is no need for it to be a base class, either; just use
> > object.
> >
> > Kent
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081229/29bc733c/attachment-0001.htm>


More information about the Tutor mailing list