原文:
plaintext = input("Please enter the text you want to compress")
filename = input("Please enter the desired filename")with gzip.open(filename + ".gz", "wb") as outfile: outfile.write(bytes(plaintext, 'UTF-8'))
修改后:
plaintext = 'Polish text: ????ńó????????ó???'filename = 'foo.gz'with gzip.open(filename, 'wb') as outfile: outfile.write(bytes(plaintext, 'UTF-8'))with gzip.open(filename, 'r') as infile: outfile_content = infile.read().decode('UTF-8')print(outfile_content)
有python的语法问题需要在read后面加上decode('UTF-8'),写数据的时候需要转换一下bytes(plaintext, 'UTF-8')
联系客服