3

Currently, I am importing every class I have in a python file in my main "Runner" script. The goal is to, based on a string given, instantiate the class that has the same name as the string given.

For example:

If there is a class called 'Test':

class Test():

if the String is "Test", it will call that class.

1 Answer 1

6

It's seems a reflection case, that are explained here.

Example from ref:

module = __import__(module_name)
class_ = getattr(module, class_name)
instance = class_()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.