Advertisement
here2share

# create_an_HTML_table.py

Jan 7th, 2015
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. # create_an_HTML_table.py
  2.  
  3. import random
  4.  
  5. def rand9999():
  6.     return random.randint(1000, 9999)
  7.  
  8. def tag(attr='', **kwargs):
  9.     for tag, txt in kwargs.items():
  10.         return '<{tag}{attr}>{txt}</{tag}>'.format(**locals())
  11.  
  12. if __name__ == '__main__':
  13.     header = tag(tr=''.join(tag(th=txt) for txt in ',X,Y,Z'.split(','))) + '\n'
  14.     rows = '\n'.join(tag(tr=''.join(tag(' style="font-weight: bold;"', td=i)
  15.                                     + ''.join(tag(td=rand9999())
  16.                                               for j in range(3))))
  17.                      for i in range(1, 6))
  18.     table = tag(table='\n' + header + rows + '\n')
  19.     print(table)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement