__getattribute__

  • Thread starter Daniel =?ISO-8859-1?Q?Sch=FCle?=
  • Start date
D

Daniel =?ISO-8859-1?Q?Sch=FCle?=

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
 
P

Peter Hansen

Daniel said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top