Created
May 19, 2011 08:54
-
-
Save c4urself/980431 to your computer and use it in GitHub Desktop.
make an html tag in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#tag('ul',''.join([tag('li',i) for i in xrange(1,6)]),{'class':'required'}) | |
#>>>'<ul class="required"><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>' | |
def tag(tag_name='div', content='', attrs_dict={}): | |
""" | |
Makes an html tag. | |
""" | |
template = '<%s>' % ('%s>%s</%s' % ('%s' % (tag_name + '%s'),'%s','%s' % tag_name)) | |
return template % (' '.join([' %s="%s"' %(k,v) for k,v in attrs_dict.iteritems()]), content) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work with self-closing html tags like "img" btw