适当减少手机使用,有助于视力保护... 新的一年祝您:身体健康,阖家欢乐!~~

NameError: name 'unicode' is not defined

浏览量:713 作者:admin 类别:: 学习笔记 更新时间:2022-05-24 16:38:53

There is no such name in Python 3, no. You are trying to run Python 2 code in Python 3. In Python 3, unicode has been renamed to str.


Python2 的unicode 函数在 Python3 中被命名为 str。在 Python3 中使用 ·str 来代替 Python2 中的 unicode.


python 2

unicode_str = unicode('中文', encoding='utf-8')

print unicode_str.encode('utf-8')

-------------------------------------------------------------

python3


e = '''我是一个中国人'''

print(e.encode('utf-8'), e.encode('utf-8').decode())


关于博主
北京南城网络及弱电【张工】为您提供:
校园网、楼宇、村镇、园区,光纤网络覆盖,无线覆盖 华为|H3c|锐捷|爱快|panabit等品牌,路由、交换机、AC、AP 无源光网络(PON)设备,布署、调试、维运,等服务...
应急/临时光纤熔接...[藤仓22S]
博文为学习python所写:内容摘自网络、学习笔记、记事备忘。
QQ:872876353,欢迎交流学习、加Q注明来意。

诗文鉴赏

《满江红》· 岳飞
落星侵晓没,
残月半山低。
怒发冲冠,
凭栏处、潇潇雨歇。
抬望眼、仰天长啸,壮怀激烈。
三十功名尘与土,八千里路云和月。
莫等闲、白了少年头,
空悲切。
源于生活-记录日常
The site based on python 3 with flask...