Home  >  Q&A  >  body text

python - join()转义的问题

t = ['[', '"', '123', '"', ',"', 'haha', '"', ',"', '"', ',"', '**\\t', '"', ',"', '3709**********3125', '"', ',"', '', '"', ']']
print "".join(t)

>>> ["123","haha","","**\t","3709**********3125",""]

有什么办法可以让join返回的的时候不转义\,返回原始值么?

黄舟黄舟2765 days ago385

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:17:44

    Can be used

    '{!r}'.format(s)

    Make s unescaped, ok for lists

    t = list(map(lambda s:'{!r}'.format(s),t))

    To handle it uniformly.

    reply
    0
  • Cancelreply