程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python UnicodeEncodeError solution

編輯:Python

Author: Awei
Personal homepage: Flyme awei

I hope everyone can support and make progress together!

The article is helpful to you, follow, like and favorite

How to solve the UnicodeEncodeError error in Python?

UnicodeEncodeError: 'gbk' codec can't encode character '\u2708' in position 0: illegal multibyte sequence

When PyCharm runs the following code

# -*- coding: utf-8 -*-# @File : plural.py# @author: Flyme awei # @email : [email protected]# @Time : 2022/8/3 17:13# Ticket purchase pageprint('Domestic\t\t*International.Hong Kong, Macao and Taiwan\tFind low prices')print('----------------------------------------')print('flight type\t*one-way\t*round-trip\t*Multiple passes (including notch passes)')print('Departure city: Beijing')print('Arrival city: Changchun')print('Departure date:2022-3-8')print('Return date:yyyy-MM-dd')print('----------------------------------------')print('\t\t\t\t with children\[email protected] a baby')print('\n\t\t\t\t\t[Search]')

An error like UnicodeEncodeError: 'gbk' codec can't encode character '\u2708' in position 0: illegal multibyte sequence appears

The first step, click File-->Settings

The second step is to find Code Style under Editor in File Encodings, change GBK in Project Encoding: to UTF-8 and click Apply, then OK
Now let’s rerun the code and try it out
you can seeThe code works fine
UnicodeEncodeError: 'gbk' codec can't encode character '\u2708' in position 0: illegal multibyte sequence This error is solved!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved