python3报错 name ‘unicode’ is not defined
一份在python2运行正常的代码,在python3运行报错:
# 首先尝试最常见的预期格式
if isinstance(date_input, unicode): # Python 2.7特有的检查
date_input = date_input.encode('utf-8') # 转换unicode为str
原来在 Python 3.x 中,字符串默认为 Unicode 字符串,因此不再需要对 unicode 类型进行特殊处理。所以在python3不用对date_input 做特殊处理,删除上面那2行果然运行正常了。