Python 3.1.1 Problem With Tuples

Posted by Protean on Stack Overflow See other posts from Stack Overflow or by Protean
Published on 2010-03-08T09:00:37Z Indexed on 2010/03/08 9:06 UTC
Read the original article Hit count: 471

Filed under:
|
|
|

This piece of code is supposed to go through a list and preform some formatting to the items, such as removing quotations, and then saving it to another list.

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 = []
            for line in list_i:
                cache = line.split('\t')
                cacbe[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 (country_list)

However; it chokes at 'string_o += string_i[i]' and gives the following error:

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

© Stack Overflow or respective owner

Related posts about python

Related posts about tuple