Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language

Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Python Programming Language

Can string be callable as a method ?

Hi all
 I tried to scan a directory and __import__ all modules ,
imported module: help
imported module: __init__
imported module: hi
imported module: thanks

and I scaned all methods in them, and put them to a list like:

[['f_chelp', 'f_help'], [], ['f_exclaim', 'f_hi', 'random'],
['f_thanks', 'random']]

But how can I call them from that list??

Thank you.

Jia Lu

['__doc__', '__file__', '__name__', 'acos', 'asin', ... ]

>>> math.__dict__['acos'](0)
>>> getattr(math, 'asin')(0)


Instead of storing the names of the functions, better to store the
functions themselves:

>>> my_list = [math.acos, math.asin]
>>> my_list[0](1)


Hope this helps,


Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc