__getattribute__

Peter Hansen peter at engcorp.com
Mon Jul 12 04:12:46 CEST 2004


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



More information about the Python-list mailing list