0
私はこのコードを以下の通り実行し、圧縮部分について助けをしました。コードが動作していないと私はそれを修正する方法を理解していない。私のクラスではまだ初心者なので、あまりにも良くない。また、ユーザーに文章を求めるときに、なぜ文を入力してください。位置が与えられた後にユーザーの文章を圧縮する
import gzip
File = open('Users Sentence.txt', 'w')
Sentence = input(b"Please input a sentence ")
print (Sentence)
varNameIn = Sentence.encode('utf8')
Lower = Sentence.lower()
Splitsentence = Lower.split()
Userfile = File.write(Sentence)
varNameIn = Splitsentence
varNameOut = gzip.compress(varNameIn)
print(varNameOut)
varNameDecon = gzip.decompress(varNameOut)
print(varNameDecon.decode('utf-8'))
positions = {Splitsentence:index for index, Splitsentence in reversed(list(enumerate(Splitsentence, 1)))}
fileposition = (' '.join(str(positions.get(word)) for word in Splitsentence))
print (fileposition)
Userfile = File.write(fileposition)
File.close()
それは私にこのエラーメッセージを与え、私はそれを理解していない:
Traceback (most recent call last):
File "\\USER-PC\Users\user\Documents\homework\CW Computing\2.py", line 11, in <module>
varNameOut = gzip.compress(varNameIn)
File "C:\Python34\lib\gzip.py", line 624, in compress
f.write(data)
File "C:\Python34\lib\gzip.py", line 343, in write
self.crc = zlib.crc32(data, self.crc) & 0xffffffff
TypeError: 'list' does not support the buffer interface
感謝を。私の注釈付き
ワイルド推測:あなたは、リストを圧縮することはできません。文字列など、何か他のものを圧縮してみてください。 – Kevin
ドキュメントは少し不明ですが、['bytes'](https://docs.python.org/3/library/functions.html#bytes)のようなオブジェクトしか圧縮できないと思います。 –
'pickle'を' gzip'で圧縮して 'list'を圧縮します –