Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111773 > unrolled thread
| Started by | Michael Selik <michael.selik@gmail.com> |
|---|---|
| First post | 2016-07-22 20:32 +0000 |
| Last post | 2016-07-22 20:32 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Dynamically call methods where method is known by address vs name Michael Selik <michael.selik@gmail.com> - 2016-07-22 20:32 +0000
| From | Michael Selik <michael.selik@gmail.com> |
|---|---|
| Date | 2016-07-22 20:32 +0000 |
| Subject | Re: Dynamically call methods where method is known by address vs name |
| Message-ID | <mailman.65.1469219570.22221.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web