在开始之前,我使用的当前代码如下:
with open(classFileName,"a+"): as openFile
fileData = openFile.readlines()
try:
fileData = zlib.decompress(str(fileData))
except:
pass
with open(classFileName,"a+") as openFile:
openFile.write(fileData)
with open(classFileName,"a+") as openFile:
fileData = []
fileData = openFile.readlines()
fileData.append(mergedData)
fileData = sorted((a.strip().split() for a in fileData),key=operator.itemgetter(1))
fileData = os.linesep.join(p[0] + ' ' + p[1] for p in fileData)
fileData = str(fileData)
zlib.compress(fileData)
with open(classFileName,"w") as openFile:
openFile.write(fileData)
然而,这实际上抛出了一个错误,说在最后一行上应该有一个字符缓冲区对象。在
该文件的示例如下所示:
锐斯5号
约翰7
亚历克斯2
有什么建议或帮助吗?我想压缩以减少操纵分数。因为我这样做的原因看起来更好。不用担心原因。在
Python中的字符串是不能更改的(字节对象也是如此),因此,即使不查看文档,也可以推断出
zlib.compress
不能修改您的fileData{
。上面的代码片段只记录了原始的fileData。在来自the documentation:
所以
应该为你工作。在
相关问题 更多 >
编程相关推荐