post
poster: toraton
description: Simple html module
language: Python
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import types

def div(obj=None):
    output     = ''
    attributes = {}
    inner      = ''

    for item in obj:
        if obj.index(item) == 0:
            if type(item) == types.DictionaryType:
                attributes = item
            else:
                attributes = None
                inner      = item
        else:
            inner += item
    if type(attributes) == types.DictionaryType:
        output = "<div%s>%s</div>" % (" "+" ".join(["%s=\"%s\"" % (k, v) for k, v in attributes.items()]), str(inner))
    elif attributes is None:
        output = "<div>%s</div>" % str(inner)

    
    return output