Created
January 28, 2014 18:33
-
-
Save halit/8673385 to your computer and use it in GitHub Desktop.
html wrapper
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
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