Variable class name in python

Joined
Apr 25, 2022
Messages
1
Reaction score
0
Is it a good coding practice to have the class name as variable.

E.g:

Code:
def create_class(class_name):
   class class_name:
     def __init__(self):
       do_sth....
   class_instance = class_name()
   return class_instance


for object in objects:
      res = create_class(object)

I wanted to create different classes which are present in a list like objects=[person,vehicle, location ..]. What could be other alternative way to do it ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top