解决pycharm在debug console中输入中文UnicodeEncodeError的问题
程序员文章站
2022-03-03 07:53:35
...
使用pycharm在debug python 2时,无法在debug console中输入中文,输入中文便会提示如下错误:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-2: ordinal not in range(128)
直接导致带有中文的代码在进行debug时极不方便,解决方法如下:
\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\(版本号)\helpers\pydev\pydevconsole.py
将以上文件中的代码片段
def console_exec(thread_id, frame_id, expression, dbg):
"""returns 'False' in case expression is partially correct
"""
frame = pydevd_vars.find_frame(thread_id, frame_id)
expression = str(expression.replace('@[email protected]', '\n'))
改为
def console_exec(thread_id, frame_id, expression, dbg):
"""returns 'False' in case expression is partially correct
"""
frame = pydevd_vars.find_frame(thread_id, frame_id)
if isinstance(expression, unicode):
expression = unicode(expression.replace('@[email protected]', '\n'))
else:
expression = str(expression.replace('@[email protected]', '\n'))
保存退出,重启pycharm,便可完美兼容中文。
上一篇: 前端开发平时笔记记录
下一篇: Scrapy插入Mysql数据库(多表)