打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
TypeError: 'str' does not support the buffer interface
原文:
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')
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
PostgreSQL数据库学习手册之备份和恢复
解决 python 中读写文件的终极方案 UnicodeDecodeError: 'gbk' cod...
盘点 App 逆向中常见的加密算法!
Flex中实现对ZIP文件的解析 | 中文Flex例子
Perl的简单语法(与C语言语法的异同)3
python 给定URL 如何获取其内容,并将其保存至HTML文档。
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服