Python DBF:“ascii”编解码器无法解码位置6中的字节0xf6:序号不在范围(128)内

2024-05-23 14:26:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个字符串,其中包含我想您会称之为“特殊”字符(o上面有一个元音变音符)的字符串,它正在抛出我正在使用的DBF库(Ethan Furman的Python DBF库https://pypi.python.org/pypi/dbfretrieve_character()函数,函数最后一行的错误是'ascii' codec can't decode byte 0xf6 in position 6: ordinal not in range(128))。

代码:

def retrieve_character(bytes, fielddef, memo, decoder):
    """
    Returns the string in bytes as fielddef[CLASS] or fielddef[EMPTY]
    """
    data = bytes.tostring()
    if not data.strip():
        cls = fielddef[EMPTY]
        if cls is NoneType:
            return None
        return cls(data)
    if fielddef[FLAGS] & BINARY:
        return data
    return fielddef[CLASS](decoder(data)[0]) #error on this line

Tags: 函数字符串inpypidatareturnifbytes