#!/usr/bin/python3 # -*- coding: utf-8 -*- str_1 = '这是中文' # str print(str_1)
报错:
UnicodeEncodeError: ‘latin-1’ codec can’t encode characters in position 0-3: ordinal not in range(256)
str_2 = str_1.encode(“utf-8”).decode(“latin1”)
str_1 = '这是中文' # str str_2 = str_1.encode("utf-8").decode("latin1") print(str_2)
输出: