纯粹是为了记录
文件位置
D:\ProgramData\Anaconda3\envs\XXXX\Lib\site-packages\rpy2\rinterface_lib\conversion.py
修改方式
def _cchar_to_str(c, encoding: str) -> str:
# TODO: use isString and installTrChar
try:
s = ffi.string(c).decode(encoding)
except Exception as e:
s = ffi.string(c).decode('GBK')
return s
def _cchar_to_str_with_maxlen(c, maxlen: int, encoding: str) -> str:
# TODO: use isString and installTrChar
try:
s = ffi.string(c, maxlen).decode(encoding)
except Exception as e:
s = ffi.string(c, maxlen).decode("GBK")
return s
参考链接
Python调用R出现“UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb2” 问题
文章讨论了在RPy2的conversion模块中,如何处理从C字节串到Python字符串时遇到的UnicodeDecodeError,特别是在使用`cchar_to_str`和`cchar_to_str_with_maxlen`函数时,如果源数据不是UTF-8编码,如何适当地使用GBK编码进行解码。
1240

被折叠的 条评论
为什么被折叠?



