python中怎么用类创建对象
发布网友
发布时间:2022-04-21 07:51
我来回答
共1个回答
热心网友
时间:2022-05-10 21:51
class BaseObject(object):
def __init__(self, **kwg):
self.__dict__ = dict(kwg)
content = '''Tim.Wang|M|43
Bruce.Wang|M|38
Amay.Song|F|21'''
def ln2obj(ln):
name,sex,age = ln.split('|')
return BaseObject(name=name,sex=sex,age=int(age))
students = map(ln2obj, content.splitlines())