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. Advertising

  2. srinivasan srinivas

    r Guest

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

    5.0
    r, Jul 30, 2009
    #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. Joseph Cook

    Switching obect's type--sort of.

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

    dynamic obect access

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

    dynamic obect access

    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    287
    Masudur
    Jul 15, 2007
  4. Replies:
    9
    Views:
    237
    Timothy Grant
    Aug 27, 2008
  5. Iver Erling Årva
    Replies:
    2
    Views:
    88
    Iver Erling Årva
    Aug 19, 2004
Loading...

Share This Page