方法一:
class Date:def __init__(self, year, month, day):self.year = yearself.month = monthself.day = dayd = Date.__new__(Date)print(d)data = {'year': 2012, 'month': 12, 'day': 21}for key, value in data.items():setattr(d, key, value)print(d.year)
方法二:
from time import localtimeclass Date2:def __init__(self, year, month, day):self.year = yearself.month = monthself.day = day@classmethoddef today(cls):d = cls.__new__(cls)t = localtime()d.year = t.tm_yeard.month = t.tm_mond.day = t.tm_mdayreturn dprint(Date2.today().year)
