我有很多这样的课程:
class playlist_type_1(radio):
'''child class'''
def __init__(self,user, type):
radio.__init__(self, user, type)
class playlist_type_2(radio):
'''child class'''
def __init__(self,user,type):
radio.__init__(self, user, type)
它们继承自:
class radio(self, user, type):
'''parent class'''
因为我将有许多users
,所以我尝试构建一个模型来创建这样的实例:
thom = playlist_type1('Thom Yorke', 'playlist_type_1')
用户本人thom
将通过以下方式选择位于command line
的playlist_type_n
:
string = raw_input('Choose a playlist type> ')
实例将被创建并运行:
thom = playlist_type1('Thom Yorke', string)
这能在class scope
内实现吗?你知道吗
创建名称到类的映射,然后基于该映射实例化类:
相关问题 更多 >
编程相关推荐