470,849 Members | 1,344 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

__getattribute__

Hello NG

is this kind of usage possible for classes
l = [1, 2, 3, 1]
l.__getattribute__("count")(1)

for example
f = foo()

def bar(t, m, p):
t.__getattribute__(m)(p)
regards

Daniel
Jul 18 '05 #1
1 2189
Daniel Schüle wrote:
is this kind of usage possible for classes
l = [1, 2, 3, 1]
l.__getattribute__("count")(1)


Yes, but for various reasons it's spelled like this:

c:\>python
Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on
win32
l = [1, 2, 3, 1]
getattr(l, "count")(1)

2

Under the covers it uses __getattr__ (and it's surprising
you didn't find that in your searches for this), but
you shouldn't call that directly, normally.

-Peter
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Gigi | last post: by
3 posts views Thread by Sylvain Ferriol | last post: by
5 posts views Thread by Stefan Sonnenberg-Carstens | last post: by
6 posts views Thread by Adam Donahue | last post: by
8 posts views Thread by bukzor | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.