console.py 文件源码

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

项目:eyeD3 作者: nicfit 项目源码 文件源码
def _encode(s):
    '''This is a helper for output of unicode. With Python2 it is necessary to
    do encoding to the LOCAL_ENCODING since by default unicode will be encoded
    to ascii. In python3 this conversion is not necessary for the user to
    to perform; in fact sys.std*.write, for example, requires unicode strings
    be passed in. This function will encode for python2 and do nothing
    for python3 (except assert that ``s`` is a unicode type).'''
    if compat.PY2:
        if isinstance(s, compat.unicode):
            try:
                return s.encode(LOCAL_ENCODING)
            except Exception as ex:
                log.error("Encoding error: " + str(ex))
                return s.encode(LOCAL_ENCODING, "replace")
        elif isinstance(s, str):
            return s
        else:
            raise TypeError("Argument must be str or unicode")
    else:
        assert(isinstance(s, str))
        return s
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号