0

I currently have an import called utilities

In this import there are two functions, utilities.func_1 and utilities.func_2

Now I know I can do print(dir(utilities)) to see the dictionary of functions this object has. In this case it outputs

['PIPE', 'Popen', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'func_1', 'func_2']

My question is assume I have the string x = 'func_1' how would I go about being able to say, call the utilities function from this string.

So for example, how would I get the result of this

utilities.func_1(var1, var2)

by typing something like this

x = 'func_1'
utilities.x(var1, var2)
nadermx
  • 2,596
  • 7
  • 31
  • 66
  • 2
    Does this answer your question? [Calling a function of a module by using its name (a string)](https://stackoverflow.com/questions/3061/calling-a-function-of-a-module-by-using-its-name-a-string) – joshmeranda Aug 29 '21 at 23:43
  • yes, although I wont delete my question, as I feel the question is still relevant. – nadermx Aug 31 '21 at 03:46

0 Answers0