calling obect method

Discussion in 'Python' started by srinivasan srinivas, Jul 30, 2009.

  1. Hi,
    I would like to know if i have an object and one of its methods as a string. How to call the method using this string?
    For ex
    If object is x and string y has one of its method names.
    x.value(y)() ---. Is there a way to do this?

    Thanks,
    Srini


    See the Web's breaking stories, chosen by people like you. Check out Yahoo! Buzz. http://in.buzz.yahoo.com/
     
    srinivasan srinivas, Jul 30, 2009
    #1
    1. Advertisements

  2. srinivasan srinivas

    r Guest

    >>> import math
    >>> getattr(math, 'hypot')(3,4)

    5.0
     
    r, Jul 30, 2009
    #2
    1. Advertisements

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. Jabel D. Morales - VMan of Mana

    Problems with JNI: calling a Java method from native method.

    Jabel D. Morales - VMan of Mana, Aug 1, 2003, in forum: Java
    Replies:
    1
    Views:
    5,297
    Joseph Millar
    Aug 1, 2003
  2. Joseph Cook

    Switching obect's type--sort of.

    Joseph Cook, Nov 21, 2003, in forum: C++
    Replies:
    7
    Views:
    531
    Howard
    Nov 21, 2003
  3. pelegk1

    dynamic obect access

    pelegk1, Jul 15, 2007, in forum: .NET
    Replies:
    0
    Views:
    385
    pelegk1
    Jul 15, 2007
  4. =?Utf-8?B?cGVsZWdrMQ==?=

    dynamic obect access

    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    371
    Masudur
    Jul 15, 2007
  5. Replies:
    9
    Views:
    355
    Timothy Grant
    Aug 27, 2008
  6. Iver Erling Årva
    Replies:
    2
    Views:
    145
    Iver Erling Årva
    Aug 19, 2004
  7. why-em-jay

    Calling a method of the calling object ...

    why-em-jay, Sep 15, 2005, in forum: Perl Misc
    Replies:
    3
    Views:
    389
    Anno Siegel
    Sep 15, 2005
  8. Daz
    Replies:
    7
    Views:
    198
Loading...