网络数据传输--编码转换,不定长参数传递,字符串拼接,URLencode编码



import urllib.parse


def a(name, **kwargs):
    return b(**kwargs)


def b(**kwargs):
    return c(**kwargs)


def c(**kwargs):
    args = []
    for k, v in kwargs.items():
        para = v.encode("utf-8") if isinstance(v, str) else str(v)
        args.append("{0}={1}".format(k, urllib.parse.quote(para)))
    return "&".join(args)


res = a("name", a=1, b=2, c=3)
print(res)


# 输出结果
a=1&b=2&c=3

posted @ 2020-06-05 20:01  yblackd  阅读(136)  评论(0编辑  收藏  举报