[Tutor] Fwd: Class Extend Help

Omer Jaggojaggo+Py at gmail.com
Tue Dec 23 15:31:54 CET 2008


Hey!

Thx for the help,

@Martin,
At the moment my only need is basic retrievals of source code of basic files
from the internet, so no need for urllib2 or response objects just yet.


Now, copying and pasting line by line into the interactive mode I get this:

>>> 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?


On Sat, Dec 20, 2008 at 6:49 PM, Richard Lovely
<roadierich at googlemail.com>wrote:

> There are three ways as I see it: using __getattr__, using a new init,
> or using a property decorator.  The last two are probably the most
> pythonic, but I'm not familiar with decorators, so here's how I'd do
> the second of the three:
>
> try:
>     from google.appengine.api.urlfetch import fetch
> except:
>     from urllib import urlopen
>
>      class fetch(urlopen):
>         def __init__(self, *args):
>             urlopen.__init__(self, *args)
>             self.content = self.read()
>
>
> This probably doesn't behave exactly the same way as the google class,
> but it should be similar enough?
> ---
> Richard "Roadie Rich" Lovely, part of the JNP|UK Famile
> www.theJNP.com
>
>
>
> 2008/12/20 Omer <Jaggojaggo+Py at gmail.com <Jaggojaggo%2BPy at gmail.com>>:
> > Hey.
> >
> > I'm trying to do something I think is basic and am failing.
> >
> > The goal is:
> > [mimicking the google urlopen syntax]
> >
> > try:
> >     from google.appengine.api.urlfetch import fetch
> > except:
> >     from urllib import urlopen as fetch
> >
> >
> > How do I add this "fetch" the property of content?
> >
> > I basically want fetch(url.com).content to replace urlopen(url.com
> ).read()
> >
> > Mind, content is not a method.
> >
> > Thoughts?
> >
> > Thx. Omer.
> >
> >
> > _______________________________________________
> > 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/20081223/9c1a278b/attachment.htm>


More information about the Tutor mailing list