'str' nicht unterstützt buffer-Schnittstelle Python ist3 von Python2

Hallo habe diese zwei Funktionen in Py2 funktioniert gut, aber es nicht funktioniert auf 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

Die Konsole ouputs:

Traceback (most recent call last):
  File "Practica2.py", line 83, in <module>
    large = encoding(text, codes)
  File "Practica2.py", line 56, in encoding
    f.write('%s' % binary)
TypeError: 'str' does not support the buffer interface
Sie müssen Stimmen, um bytes oder öffnen in "wt" Modus, wenn mit python 3.4
'w' reicht.
docs.python.org/3/tutorial/... - Hinweis: änderungen von 2.x.
möglich, Duplikat der TypeError: 'str' nicht unterstützt buffer interface

InformationsquelleAutor Daniel Domingo | 2014-11-15

Schreibe einen Kommentar