给定一个函数,如:
import six
def convert_to_unicode(text):
"""Converts `text` to Unicode (if it's not already), assuming utf-8 input."""
if six.PY3:
if isinstance(text, str):
return text
elif isinstance(text, bytes):
return text.decode("utf-8", "ignore")
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
elif six.PY2:
if isinstance(text, str):
return text.decode("utf-8", "ignore")
elif isinstance(text, unicode):
return text
else:
raise ValueError("Unsupported string type: %s" % (type(text)))
else:
raise ValueError("Not running on Python2 or Python 3?")
由于six处理了 python2 和 python3 的兼容性,上述convert_to_unicode(text)函数是否等同于 just six.text_type(text)?IE
def convert_to_unicode(text):
return six.text_type(text)
是否存在原始convert_to_unicode捕获但six.text_type不能捕获的情况?
慕的地6264312
相关分类