how to dynamically create an instance of a class in python?

后端 未结 7 1601
我寻月下人不归
我寻月下人不归 2020-12-01 06:09

I have list of class names and want to create their instances dynamically. for example:

names=[
\'foo.baa.a\',
\'foo.daa.c\',
\'foo.AA\',
 ....
]

def save(c         


        
相关标签:
7条回答
  • 2020-12-01 06:52

    Best Answer I found: Better Way is to make a dictionary: objects ={} Names =[object1,object2, object3]

    For objname in Names: objects[objname]=classname()

    Found in: https://www.thecodingforums.com/threads/create-object-name-from-string-value.712461/

    0 讨论(0)
提交回复
热议问题