在Python中是否可以通过字典实例化一个类?
shapes = {'1':Square(), '2':Circle(), '3':Triangle()} x = shapes[raw_input()]
我想让用户从菜单中选择,而不是在输入上编写大量if else语句.例如,如果用户输入2,则x将是Circle的新实例.这可能吗?
python dictionary class
class ×1
dictionary ×1
python ×1