search

Home  >  Q&A  >  body text

javascript - js code to python

js code is as follows

var e = a.charCodeAt(t).toString(16);这一行不明白
function encode_unicode_param(a) {
    for (var s = "", t = 0; t < a.length; t++) {
        var e = a.charCodeAt(t).toString(16);
        s += 2 == e.length ? "n" + e: e
    }
    return s
}
高洛峰高洛峰2709 days ago918

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-06-22 11:53:54

    python3 Next:

    def encode_unicode_param(s):
        results = []
        for char in s:
            h = hex(ord(char))[2:]
            format_string = 'n{}' if len(h) == 2 else '{}'
            results.append(format_string.format(h))
        return ''.join(results)

    reply
    0
  • Cancelreply