关于python中的Unicode编码问题

发布时间 2023-05-05 16:15:20作者: 乐swap火

https://www.zhihu.com/question/35584979/answer/274675706

https://www.cnblogs.com/hackerl/p/4963642.html

python中字符串有两种形式:

str和Unicode

如果是Unicode,使用print输出就是Unicode的字节形式,需要使用decode转一下才显示正常

另外发现python 中

path = u'.'

for main_dir, sub_dir_list, sub_file_list in os.walk(path):
        print main_dir.decode(encoding='utf-8'),1 #正常显示
        print (main_dir.decode(encoding='utf-8'),1) 

 

print函数,带括号和不带括号是不相同了,比较奇怪