0

I'm trying to run a function that is inside a string variable in Python. The code I'm using is:

def func1():
    return "Hello"

word = "func1()"
a = exec(word)
print(a)

But, instead of returning Hello, the script returns None.

Is it possible to run a command that I have in a string variable?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Wolf
  • 17
  • 4

0 Answers0