weixin_39942191 2020-11-20 20:33
浏览 0

six u() breaks for existing unicode strings for Python 2

Originally reported by: James Cleveland (Bitbucket: radiosilence, GitHub: radiosilence)

Code:

import six; six.u(u'bawbag')

Error:

TypeError: decoding Unicode is not supported

I would suggest adding this in the u(s) function:

    if isinstance(s, unicode):
        return s

So that it behaves like the unicode() function, IE: liberal in what you accept, conservative in what you produce.

  • Bitbucket: https://bitbucket.org/gutworth/six/issue/45

该提问来源于开源项目:benjaminp/six

  • 写回答

11条回答 默认 最新

  • weixin_39942191 2020-11-20 20:33
    关注

    Original comment by alex (Bitbucket: alexssb, GitHub: Unknown):

    Six not solve the problem below, which causes the test fails

    Python 3.4 (Linux)

    https://github.com/eduardtomasek/lz-string-python/blob/master/test.py#L9

    Python 2.7 (Linux) - * Compatibility using six. *

    https://github.com/alexsilva/lz-string-python/blob/master/test.py#L11

    s = six.u('Žluťoučký kůň úpěl ďábelské ódy!')

    Only works in both cases, when I use the u prefix 'u'

    u'Žluťoučký kůň úpěl ďábelské ódy!'

    评论

报告相同问题?