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 <[email protected]>:
> 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 - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor