__getattribute__

Discussion in 'Python' started by Daniel =?ISO-8859-1?Q?Sch=FCle?=, Jul 12, 2004.

  1. 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
    Daniel =?ISO-8859-1?Q?Sch=FCle?=, Jul 12, 2004
    #1
    1. Advertising

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

    Peter Hansen Guest

    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
    Peter Hansen, Jul 12, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Carlo v. Dango

    properly implementing the __getattribute__()

    Carlo v. Dango, Oct 6, 2003, in forum: Python
    Replies:
    3
    Views:
    695
    John J. Lee
    Oct 8, 2003
  2. Ruud de Jong
    Replies:
    6
    Views:
    465
    Shalabh Chaturvedi
    Mar 1, 2004
  3. Henry 'Pi' James

    Renaming __getattribute__ (PEP?)

    Henry 'Pi' James, Dec 13, 2004, in forum: Python
    Replies:
    2
    Views:
    299
    Nick Coghlan
    Dec 13, 2004
  4. Gigi
    Replies:
    0
    Views:
    453
  5. Sylvain Ferriol

    __getattribute__ for class object

    Sylvain Ferriol, Aug 12, 2005, in forum: Python
    Replies:
    3
    Views:
    278
    Steven Bethard
    Aug 12, 2005
Loading...

Share This Page