I am trying to save a class written in string format to a database, then read this and load the class as literal class.
How can I do this?
test = """
class Test:
def __init__(self, test_name):
self.test_name = test_name
def print_name(self):
print(self.test_name)
"""
Test = eval(test)
test_obj = Test(test_name='test1')
It would be better together if I also know how to save the object instance in string format since I will save the instance to the database as well, like saving pickle.
Many thanks.