0
我不斷收到這個錯誤「TypeError:'str'不支持緩衝區接口」不知道發生了什麼問題。任何援助將是偉大的。任何想法如何解決TypeError:'str'不支持緩衝區接口?
import zlib
#User input for sentnce & compression.
sentence = input("Enter the text you want to compress: ")
com = zlib.compress(sentence)
#Opening file to compress user input.
with open("listofwords.txt", "wb") as myfile:
myfile.write(com)
這篇文章可以幫助你解決問題[「STR」不支持緩衝區接口(http://stackoverflow.com/questions/26945613/str -does-not-support-the-buffer-interface-python3-from-python2):) –
謝謝,我來看看! – Trent
使用'zlib.compress(sentence.encode('utf-8'))'(如果你喜歡utf-8)使你的unicode字符串成爲字節對象而不是 –