[Tutor] Fwd: Class Extend Help
Richard Lovely
roadierich at googlemail.com
Tue Dec 23 17:03:41 CET 2008
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> 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
>
More information about the Tutor
mailing list