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


Groups > comp.lang.python > #111773

Re: Dynamically call methods where method is known by address vs name

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Michael Selik <michael.selik@gmail.com>
Newsgroups comp.lang.python
Subject Re: Dynamically call methods where method is known by address vs name
Date Fri, 22 Jul 2016 20:32:37 +0000
Lines 26
Message-ID <mailman.65.1469219570.22221.python-list@python.org> (permalink)
References <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com> <CAGgTfkPoXNo9h5LXrMxvYUA9mLbHEdsaT5Y_6FnZVm169uGHPw@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de +bcV4/WMjjzRpjkEDMgy1QapHgXMB3bgCgvx8Hvfd8NA==
Return-Path <michael.selik@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; '22,': 0.09; '[1]:': 0.09; '[2]:': 0.09; '[3]:': 0.09; 'subject:method': 0.09; '&gt;&gt;&gt;': 0.15; "'address'": 0.16; '2016': 0.16; '[4]:': 0.16; 'malcolm': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:where': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'to:2**1': 0.21; 'for?': 0.23; 'header:In-Reply- To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'name?': 0.29; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'to:addr:python.org': 0.40; 'jul': 0.72; '(better': 0.84; 'subject:address': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=Iw3cImO8/cOF2QleCGk0U348gPg69kbkF1tsLU/y8Us=; b=mRwFF3EXP78rZ0lBOiWJ3okvVLip+BEtpG/+AKK6cKdigLq2jbvDL7DjtHRF/K3X1x W3X+zYBgycWPgecF9U3tDFACL8lKTnCPS4zBpnVmz/sID83HI36jqI6Ysr+RwT6YVHy2 bg5ugqOi5kFdsdDJRewOits5FdmYLxK5V3dAhSDzebYydBfOqW0lmus19fssKlpFZ6NC FjUx2i660tAaZMIHZiFRCw+37C04ju1WBnbyhiaMPJ1vRP0nOMwkNrc4Q+BlS622XT85 vqhKWlR+3cl6IfvYrtc7N5dT8TVTbRWY3qNkSDgmQeo8j8q4CMvMLqusvjy5vOSQcum3 msEQ==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=Iw3cImO8/cOF2QleCGk0U348gPg69kbkF1tsLU/y8Us=; b=dYCbDV4bTNNJtdjz85UZ0Igsyeub5JSmO8XXAoueTWI4WHk82/CE3KM7MCl4IUkrDi 1q0RW1Jdmzhn8XzU8tqjiZG4tHRVG5rRd3it7SQgqz4LPyYNvLfZ4KuquY7X/m4OtD8o JuNipot4IW9/l96thLNgRXhgKp0KhikBHhh+qn54Vjggcr3iyJk3dXpz4rmLBFJV2jQ7 AC9JXwa/80pcp4asb6pCCHj0mue2rWeStislHTmAWeEBN101amg6tRaY+GLTXmm9nnAV FUBgVB1HUimnYhRPDyzaLFzhcRFLxtmX1J5XlB5zKk3GxznAkdOvVtWORfMQfJo5FlAX S4HA==
X-Gm-Message-State ALyK8tKsoqyd1pI2SIBXAKtXaBgwDLh8AALxwzptyl4SZktr60lkoBOD6KB4k8TIYGsGS8CejqpuFEZnxGreeQ==
X-Received by 10.36.1.12 with SMTP id 12mr40680754itk.30.1469219567268; Fri, 22 Jul 2016 13:32:47 -0700 (PDT)
In-Reply-To <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com>
X-Content-Filtered-By Mailman/MimeDel 2.1.22
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
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>
X-Mailman-Original-Message-ID <CAGgTfkPoXNo9h5LXrMxvYUA9mLbHEdsaT5Y_6FnZVm169uGHPw@mail.gmail.com>
X-Mailman-Original-References <1469217868.1572637.674159593.622C5164@webmail.messagingengine.com>
Xref csiph.com comp.lang.python:111773

Show key headers only | View raw


On Fri, Jul 22, 2016 at 4:05 PM Malcolm Greene <python@bdurham.com> wrote:

> I know I can do the following:
>
> >>> s = 'lower'
> >>> getattr(s, 'upper')()
> 'LOWER'
>
> But how could I do the same if I had the method 'address' (better
> name???) vs. method name?
>
> >>> upper_method = s.upper
>
> How do I combine this upper_method with string s to execute the method
> and return 'LOWER'?
>

In [1]: s = 'hello'
In [2]: f = s.upper
In [3]: f()
Out[3]: 'HELLO'
In [4]: g = str.upper
In [5]: g(s)
Out[5]: 'HELLO'

Is that what you're looking for?

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


Thread

Re: Dynamically call methods where method is known by address vs name Michael Selik <michael.selik@gmail.com> - 2016-07-22 20:32 +0000

csiph-web