【发布时间】:2016-01-25 09:23:54
【问题描述】:
我想将照片数据存储在 python 的文件中。但是我的文件中有一些奇怪的字符,所以这些文件无法正确打开。 我要做的是在将其保存到文件之前从我的数组中删除这些数据:
def save_foto(self):
""" Save foto data to a file """
self.data_aux = ''
last = 0
self.data_list = list(self.vFOTO)
for i in range(0,len(self.vFOTO)):
if(self.vFOTO[i]=='\x90' and self.vFOTO[i+1]=='\x00' and self.vFOTO[i+2]=='\x00' and self.vFOTO[i+3]=='\x00'
and self.vFOTO[i+4]=='\x00' and self.vFOTO[i+5]=='\x00' and self.vFOTO[i+6]=='\x00' and self.vFOTO[i+7]=='\x00'
and self.vFOTO[i+8]=='\x00' and self.vFOTO[i+9]=='\x00'):
aux1=''.join(map(chr,self.data_list[last:i]))
self.data_aux = self.data_aux+aux1
i=i+10
last=i
但我得到了错误
"TypeError: an integer is required (got type str)" on line aux1=''.join(map(chr,self.data_list[last:i]))。
有人可以帮我解释一下这是怎么回事吗? 提前致谢。
【问题讨论】:
-
错误告诉你,你正在通过使用 map() 将字符串传递给函数 chr()。我不知道 self.data_list 是什么,但它看起来像一个字符串列表。
-
你认为
chr是做什么的?你为什么叫它?
标签: python string image join integer