obsidian-execute-code icon indicating copy to clipboard operation
obsidian-execute-code copied to clipboard

运行Python代码时,如果字符串是中文,超过6个字符就会报错

Open xingkongmanbu opened this issue 2 years ago • 2 comments

运行Python代码时,如果字符串是中文,超过6个字符就会报错例如print('你好呀')则会直接报错 File "", line 3 __print_5869740145470972_1684765595195(eval( ^ SyntaxError: (unicode error) 'gbk' codec can't decode byte 0x80 in position 70: illegal multibyte sequence File "", line 1 __globals_26638759782001364_1684765595195 IndentationError: unexpected indent

File "", line 1 )) IndentationError: unexpected indent File "", line 1 except SyntaxError: IndentationError: unexpected indent File "", line 1 exec( IndentationError: unexpected indent File "", line 0

SyntaxError: (unicode error) 'gbk' codec can't decode byte 0x80 in position 70: illegal multibyte sequence

File "", line 1 __globals_26638759782001364_1684765595195 IndentationError: unexpected indent File "", line 1 ) IndentationError: unexpected indent File "", line 1 except Exception as e: ^^^^^^ SyntaxError: invalid syntax File "", line 1 __print_5869740145470972_1684765595195 (e, file=sys.stderr) IndentationError: unexpected indent File "", line 1 finally: ^^^^^^^ SyntaxError: invalid syntax File "", line 1 __print_5869740145470972_1684765595195 ("SIGIL_BLOCK_DONE_0.8545975725657418_1684765595230_39", end="") IndentationError: unexpected indent

xingkongmanbu avatar May 22 '23 14:05 xingkongmanbu

image if you use windows os, try by this: https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window

AINightCoder avatar Aug 05 '23 01:08 AINightCoder

image 从地区设置中修改为UTF-8,重启后,不会出现乱码了,但是只要命令中有中文,行首的字符就会丢失,不清楚还需要什么额外的设置

Jeremy-Merle avatar Nov 02 '23 09:11 Jeremy-Merle