-2

I am more oriented into computers programming by themselves by taking information from a user, but I have a curiosity about how to take the name of the class from a user and then create a class with that same name.

For instance,

name_of_class = input('What is the name of the class?')

and then create a class with that name

Hope you understand my question, Thank you.

Kevin Nammour
  • 13
  • 1
  • 4
  • 1
    Why do you want to do this? – alani Oct 03 '20 at 21:31
  • I don't think it exactly what you wanted, but it seems relatively similar to your question, take a look at this question: https://stackoverflow.com/questions/4821104/dynamic-instantiation-from-string-name-of-a-class-in-dynamically-imported-module – Yossi Levi Oct 03 '20 at 21:42

1 Answers1

1

As mentioned here https://stackoverflow.com/a/10555930/5480640, use the type method.

name_of_class = input('What is the name of the class?')
ClassFromInput = type(name_of_class, (object,), {})
astro not
  • 105
  • 1
  • 8