我想写与python2和python3兼容的代码。
我需要from __future__ import unicode_literals
,那么如何打印unicode字符串呢?你知道吗
文件:你好,派瑞你知道吗
# encoding=utf-8
from __future__ import print_function
from __future__ import unicode_literals
print("你好")
Python2你好,派瑞你知道吗
UnicodeEncodeError: 'ascii' codec can't encode characters in position 2-13: ordinal not in range(128)
Python3你好,派瑞你知道吗
你好
您应该使用
# -*- coding: <encoding name> -*-
头设置脚本的编码:详情请参阅PEP 263。他说
相关问题 更多 >
编程相关推荐