How can I instantiate the class stored in the raw string my_class
without having to save this string into a file first?
my_class = r'''class A:
def print(self):
print('Hello World')
'''
my_class_object = string_to_class()
my_class_object.print()
In the code above, I'm looking for an implementation of the function string_to_class()
that returns an object of the class inside my_class
.
The expected output of the code above is Hello World
.