Implement logic on object.attribute and object.attribute()

Roy Smith roy at
Sun Nov 24 15:21:47 CET 2013

In article <mailman.3131.1385302390.18130.python-list at>,
 Chris Angelico <rosuav at> wrote:

> On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano
> <steve+comp.lang.python at> wrote:
> > Not quite impossible. All you need is an object that behaves like a
> > string, except it has a __call__ method. Here's a sketch of a solution,
> > completely untested.
> >
> > class Magic_HTTP_Thing:
> >     @property
> >     def attribute(self):
> >         result = CallableStr(self.do_get())
> >         result.function = lambda: self.do_put()
> Problem with that is that it'll still call do_get immediately. You'd
> have to somehow defer this call until it's actually _used_, which is
> why I dropped a mention of "converting to str?" - which would
> presumably be a __str__ method. But I still don't like the API.
> ChrisA

If the REST interface is designed properly, all the GETs are 
nullipotent, so modulo efficiency, it should all work.

But, yeah, this seems really ugly.

More information about the Python-list mailing list