小编Dan*_*ngo的帖子

'str'不支持Python2的缓冲区接口Python3

你好Py2中的这两个功能工作正常,但它不适用于Py3

def encoding(text, codes):
    binary = ''
    f = open('bytes.bin', 'wb')
    for c in text:
        binary += codes[c]
    f.write('%s' % binary)
    print('Text in binary:', binary)
    f.close()
    return len(binary)

def decoding(codes, large):
    f = file('bytes.bin', 'rb')
    bits = f.read(large)
    tmp = ''
    decode_text = ''
    for bit in bits:
        tmp += bit
        if tmp in fordecodes:
            decode_text += fordecodes[tmp]
            tmp = ''
    f.close()
    return decode_text
Run Code Online (Sandbox Code Playgroud)

控制台输出:

Traceback (most recent call last):
  File "Practica2.py", line 83, in <module>
    large = encoding(text, codes) …
Run Code Online (Sandbox Code Playgroud)

python string unicode bytearray python-3.x

13
推荐指数
2
解决办法
5万
查看次数

标签 统计

bytearray ×1

python ×1

python-3.x ×1

string ×1

unicode ×1