1

I got this:

tu = ("func1", "func2", "func3")

And with the operation I am looking for I would get this for the first string:

moduleA.func1()

I know how to concatenate strings, but is there a way to join into a callable string?

the wolf
  • 34,510
  • 13
  • 53
  • 71
Bentley4
  • 10,678
  • 25
  • 83
  • 134
  • Your question is very unclear. "I would get this for the first string" means what? Can you show some interactive console output maybe? – Francis Avila Aug 28 '12 at 21:02

3 Answers3

5

getattr(moduleA, 'func1')() == moduleA.func1()

applicative_functor
  • 4,926
  • 2
  • 23
  • 34
2

You should use getattr builtin function. Try:

getattr(moduleA, 'func1')()
Konrad Hałas
  • 4,844
  • 3
  • 18
  • 18
0

If you mean get a function or method on a class or module, all entities (including classes, modules, functions, and methods) are objects, so you can do a func = getattr(thing 'func1') to get the function, then func() to call it.

Silas Ray
  • 25,682
  • 5
  • 48
  • 63