相关疑难解决方法(0)

TypeError:'str'不支持缓冲区接口

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(plaintext) 
Run Code Online (Sandbox Code Playgroud)

上面的python代码给出了以下错误:

Traceback (most recent call last):
  File "C:/Users/Ankur Gupta/Desktop/Python_works/gzip_work1.py", line 33, in <module>
    compress_string()
  File "C:/Users/Ankur Gupta/Desktop/Python_works/gzip_work1.py", line 15, in compress_string
    outfile.write(plaintext)
  File "C:\Python32\lib\gzip.py", line 312, in write
    self.crc = zlib.crc32(data, self.crc) & 0xffffffff
TypeError: 'str' does not support the buffer interface
Run Code Online (Sandbox Code Playgroud)

python string gzip

263
推荐指数
5
解决办法
33万
查看次数

存储Python词典

我习惯使用.csv文件将数据输入和输出Python,但是存在明显的挑战.关于在json或pck文件中存储字典(或字典集)的简单方法的任何建议?例如:

data = {}
data ['key1'] = "keyinfo"
data ['key2'] = "keyinfo2"
Run Code Online (Sandbox Code Playgroud)

我想知道如何保存它,然后如何加载它.

python json dictionary save pickle

162
推荐指数
6
解决办法
22万
查看次数

标签 统计

python ×2

dictionary ×1

gzip ×1

json ×1

pickle ×1

save ×1

string ×1