shell脚本调用python处理中文错误的问题

2025-04-17 23:32:27
推荐回答(4个)
回答1:

解决方法有两种:
一,升级到较高的版本,比如3.1.2或者以上
第二,在python安装的目录找到site.py文件(Python2x\Lib\),修改def setencoding()方法,把
def setencoding():
"""Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.""" encoding = "ascii" # Default value set by _PyUnicode_Init() if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1]
....
把if 0,改为if 1

回答2:

1.在shell里面写上编码方案
2.把utf-8 改成 gbk,据说win上对中文的支持以gbk为好。
3.如果还不行,整个错误的提示都贴出来

回答3:

恐怕是shell传给脚本运行的参数,导致过程中遇到的信息处理错误

回答4:

请在shell脚本中加上环境变量LANG的配置