Skip to content

Instantly share code, notes, and snippets.

@halit
Created January 28, 2014 18:33
Show Gist options
  • Save halit/8673385 to your computer and use it in GitHub Desktop.
Save halit/8673385 to your computer and use it in GitHub Desktop.
html wrapper
class Tag(object):
"""HTML tag class"""
def __init__(self, item, value, **atts):
"""
HTML tag constructor
"""
self.__item = item
self.__value = value
self.__attributes = [' %s="%s"' % i for i in atts.items()]
self.__element = "<{item}{attributes}>{value}</{item}>".format(
item=self.__item, attributes="".join(self.__attributes),
value=self.__value)
@property
def element(self):
"""
Element property
"""
return self.__element
@property
def item(self):
"""
Item property
"""
return self.__item
def __str__(self):
return self.__element
if __name__ == "__main__":
p_tag = Tag("p", "hello world!", id="one")
body_tag = Tag("body", p_tag)
html_tag = Tag("html", body_tag)
print html_tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment