这段代码应该经过一个列表,并对项目执行一些格式化操作,例如删除引号,然后将其保存到另一个列表。Python 3.1.1与元组有关的问题
class process:
def rchr(string_i, asciivalue):
string_o =()
for i in range(len(string_i)):
if ord(string_i[i]) != asciivalue:
string_o += string_i[i]
return string_o
def flist(self, list_i):
cache =()
cache_list = []
index = 0
for line in list_i:
cache = line.split('\t')
cache[0] = process.rchr(str(cache[0]), 34)
cache_list.append(cache[0])
cache_list[index] = cache
index += 1
cache_list.sort()
return cache_list
p = process()
list1a = ['cow', 'dog', 'sheep']
list1 = p.flist(list1a)
print (list1)
但是;它扼流圈在string_o += string_i[i]
并提供了以下错误:
Traceback (most recent call last):
File "/Projects/Python/safafa.py", line 23, in <module>
list1 = p.flist(list1a)
File "/Projects/Python/safafa.py", line 14, in flist
cacbe[0] = process.rchr(str(cache[0]), 34)
File "/Projects/Python/safafa.py", line 7, in rchr
string_o += string_i[i]
TypeError: can only concatenate tuple (not "str") to tuple
你想rchr()结果是一个字符串或元组?它不能两个:) – 2010-03-08 09:24:53