Warning:eval()
can be used to execute arbitrary Python code. You should never useeval()
with untrusted strings. (See Security of Python's eval() on untrusted strings?)
This seems simplest.
>>> class Foo(object):
... pass
...
>>> eval("Foo")
<class '__main__.Foo'>
from : https://stackoverflow.com/questions/1176136/convert-string-to-python-class-object
No comments:
Post a Comment