def tag(tagname, content="", attribs={}): before = tagname after = tagname if attribs: attribstr = d2attribs(attribs) before += ' ' + ' '.join(attribstr) return "<%s>%s" % (before, content, after) def d2attribs(d): res = u'' return ["%s=\"%s\"" % (k,v) for k,v in d.items()] #print tag('foo', content='bar', attribs=[]) #print tag('td', attribs={'id': 'x', 'class':'y'}) counter = 0 print '' print '' for i in 'abcdefghi': for j in 'ABCDEFGHI': print tag('td',attribs={'id':i+j}) counter += 1 if counter % 9 == 0 and counter != 81: print '' print '' print '
'