display.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:ITAP-django 作者: krivers 项目源码 文件源码
def formatList(node, field):
    if type(node) != list:
        return None
    s = ""
    nameMap = { "body" : "line", "targets" : "value", "values" : "value", "orelse" : "line",
                "names" : "name", "keys" : "key", "elts" : "value", "ops" : "operator",
                "comparators" : "value", "args" : "argument", "keywords" : "keyword" }

    # Find what type this is
    itemType = nameMap[field] if field in nameMap else "line"

    if len(node) > 1:
        s = "the " + itemType + "s: "
        for line in node:
            s += formatNode(line) + ", "
    elif len(node) == 1:
        s = "the " + itemType + " "
        f = formatNode(node[0])
        if itemType == "line":
            f = "[" + f + "]"
        s += f
    return s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号