Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'api.': 0.05; 'method.': 0.07; 'solution,': 0.09; 'subject:()': 0.09; 'def': 0.12; '@property': 0.16; 'defer': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'lambda:': 0.16; 'wrote:': 0.18; 'string,': 0.24; 'mon,': 0.24; 'mention': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; '25,': 0.31; "d'aprano": 0.31; 'dropped': 0.31; 'steven': 0.31; 'class': 0.32; 'quite': 0.32; 'problem': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'nov': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; '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:date:message-id:subject:from:to :content-type; bh=fqiKs3OouDNuyQhPqXNwwm1jZ6s3lyou+wzlCCRv/RA=; b=ipFKi6PlvZ246qJu1mgEgx3IqDkkPv+v5nOXBCuQnXdrBinuOVOrm4uooFPAga0SaU gF7rPcdid3xzkwyrAwtEnzc279wTbjNDxYlj8KiUfgljXYv8WkZexe6X28cB33pDD3h+ 5o3K079EOLd2hh93lVhv+eEMKkgqk2l5MwUvMGhiGqczPd11SOrO631hq/38aq03e6rG WxKUN4mfnI54rbe1THp/BoqUDVnfrLy1fPX5qm/gpHEx9RAefsBM9XfGQTb0U8DhlHQV rX95BPzMz6AgPzCsIOUTH/kY4vY7QnyGpVBhDYYhQV0tRoeWMf8Gx1HwIrCoqivlHvwX L6Og== MIME-Version: 1.0 X-Received: by 10.68.191.3 with SMTP id gu3mr1271736pbc.142.1385302386867; Sun, 24 Nov 2013 06:13:06 -0800 (PST) In-Reply-To: <529202e3$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <529202e3$0$29993$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 25 Nov 2013 01:13:06 +1100 Subject: Re: Implement logic on object.attribute and object.attribute() From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1385302390 news.xs4all.nl 15992 [2001:888:2000:d::a6]:36140 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:60368 On Mon, Nov 25, 2013 at 12:45 AM, Steven D'Aprano 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