davidsu33的专栏

#encoding=utf-8#made by davidsu33#2015-2-9from django.template import Template,Contextfrom django.conf import settingsclass Athlete:name = ''height= 0weight = 0def __init__(self, *arg):'''print('arg_couont=', len(arg))print('arg_type=', type(arg[0]))print('arg[0]=', arg[0])print('arg[0].len=', len(arg[0]))'''if type(arg[0]) == list and len(arg[0]) == 3:thelist = arg[0]self.name = thelist[0]self.height = thelist[1]self.weight = thelist[2]else :raise Exception('Invalid Argument!!!')def __str__(self):return 'name=%s, height=%d, weight=%d' % \(self.name, self.height, self.weight)if __name__ == '__main__':html = '''<html><head><title>for test for </title></head><body><ul>{% for athlete in althlete_list %}<li>{{athlete.name}} ,{{athlete.height}}, {{athlete.weight}}</li>{% endfor %}</ul></body>'''settings.configure()#name height weightsource = [['zhangsan', 180, 100], ['lisi', 168, 60],['wangwu', 175, 90],]athletes = []for i in source:athletes.append(Athlete(i))for i in athletes:print(str(i))t = Template(html)c = Context({'althlete_list': athletes})r = t.render(c)print('r=', r);#save to disk filefile_path = 'd:/test.html'f = open(file_path, 'w+')assert(not f.closed)f.write(r)f.close()

,每年的同一天和他庆祝生日,每年的情人节、圣诞节、除夕,

davidsu33的专栏

相关文章:

你感兴趣的文章:

标签云: