Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #60380

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <glicerinu@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'api.': 0.05; 'method.': 0.07; 'solution,': 0.09; 'subject:()': 0.09; 'cc:addr:python- list': 0.11; 'def': 0.12; '24,': 0.16; '@property': 0.16; 'defer': 0.16; 'lambda:': 0.16; 'wrote:': 0.18; 'finished': 0.19; 'cc:addr:python.org': 0.22; 'string,': 0.24; 'guys': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'mention': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; "d'aprano": 0.31; 'dropped': 0.31; 'initiate': 0.31; 'marc': 0.31; 'steven': 0.31; 'class': 0.32; 'quite': 0.32; 'problem': 0.35; 'knowledge': 0.35; 'except': 0.35; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'building': 0.35; 'thanks': 0.36; 'nov': 0.38; 'pm,': 0.38; 'skip:n 10': 0.64; 'places': 0.64; 'to:addr:gmail.com': 0.65; 'sharing': 0.69; 'presumably': 0.84; 'subject:skip:o 10': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=3oSIJt0lzaT87uRBFdiKvesL2yMExf8kI8GFcxFeXv0=; b=peFrOOwwBRMjLSVepj9yOkaTuai+ZPhdYcIz4MZE/MTZtgIrwVeNyjkTdzHfg5QgAm gBcV4b8eQAwXr21Hr690WAw+Y6kk4LQ4QWt4Y6g7R9TnW0xuBdaq0fbhPpCe5YqfLfJ8 asUCpEcFS9xqU1Ba0mQK8K4G+G0CBKWep9WLpmE2MYhZ8TEXPHorHTGpZDJXHeVF/C95 YZhMf+f9w98VV99YcorUV2XX90MIsNWAH7Kyvmh/8Md/8Yro4QGdcvcvaR6KUKRAASgE umh/xEsKYW8xCbnoQsFIaFpE+dQC1L4VCmT2arz5ULB0E/cfgr+cMa4GQxqNvkq3Il2x 6GLw==
X-Received by 10.58.208.130 with SMTP id me2mr21507110vec.13.1385303662815; Sun, 24 Nov 2013 06:34:22 -0800 (PST)
MIME-Version 1.0
In-Reply-To <CAPTjJmo+wNum9-5AQiX+siMtCLtkn2CVZuFnEjkM8m1R=CtcHQ@mail.gmail.com>
References <CA+DCN_uqn5OukuZ5QWWjJCUTksaFw50L03ZU7uqdm4a6ZOn7CA@mail.gmail.com> <mailman.3128.1385298299.18130.python-list@python.org> <529202e3$0$29993$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmo+wNum9-5AQiX+siMtCLtkn2CVZuFnEjkM8m1R=CtcHQ@mail.gmail.com>
From Marc Aymerich <glicerinu@gmail.com>
Date Sun, 24 Nov 2013 15:34:02 +0100
Subject Re: Implement logic on object.attribute and object.attribute()
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3138.1385304139.18130.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1385304139 news.xs4all.nl 15881 [2001:888:2000:d::a6]:42935
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:60380

Show key headers only | View raw


On Sun, Nov 24, 2013 at 3:13 PM, Chris Angelico <rosuav@gmail.com> wrote:
> On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> 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.

That's right.
In my case deferring the GET call will not be a problem since this
objects will be used in just a few particular places and the workflow
is always something like:

# Initiate firmware building
node.ctl.firmware()
# wait until finished
while node.ctl.firmware.progress < 100:
   time.sleep(1)


Thanks for sharing your knowledge guys !!
-- 
Marc

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Implement logic on object.attribute and object.attribute() Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-11-24 05:04 -0800
  Re: Implement logic on object.attribute and object.attribute() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-24 13:45 +0000
    Re: Implement logic on object.attribute and object.attribute() Devin Jeanpierre <jeanpierreda@gmail.com> - 2013-11-24 06:04 -0800
    Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:13 +1100
      Re: Implement logic on object.attribute and object.attribute() Roy Smith <roy@panix.com> - 2013-11-24 09:21 -0500
        Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:31 +1100
    Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:13 +1100
    Re: Implement logic on object.attribute and object.attribute() Marc Aymerich <glicerinu@gmail.com> - 2013-11-24 15:16 +0100
    Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:37 +1100
      Re: Implement logic on object.attribute and object.attribute() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-24 15:11 +0000
    Re: Implement logic on object.attribute and object.attribute() Marc Aymerich <glicerinu@gmail.com> - 2013-11-24 15:34 +0100
    Re: Implement logic on object.attribute and object.attribute() Marc Aymerich <glicerinu@gmail.com> - 2013-11-24 15:48 +0100
    Re: Implement logic on object.attribute and object.attribute() Chris Angelico <rosuav@gmail.com> - 2013-11-25 01:57 +1100

csiph-web