0

Hi, this is my code:

def items_string(items_list):
    """Convert a list of Id, number pairs into a string representation.

    items_string(list((str, int))) -> str
    """
    result = []
    for item_id, num in items_list:
        result.append("{0}:{1}".format(item_id, num))
    return ','.join(result)

class Compound(Item):
    def __init__(self,item_id,name,products,items_list):
        Item.__init__(self,item_id,name)
        self.products=products
        self.items_list=items_list

    def __repr__(self):
        self.items_list=items_string(self)
        return '{0},{1},{2}'.format(self.item_id,self.name,self.items_list)

class Products:
    def __init__(self):
        self.mydict={}

    def get_item(self,item_id):
       return self.mydict[item_id]

When I enter this in IDLE:
products = Products()
products.add_item('CWH111', Compound('CWH111','Mountain Bike Built Wheel', products,[('TR202', 1), ('TU227', 1), ('WH239', 1)]))
products.get_item('CWH111')

I get this error:
for item_id, num in items_list:
TypeError: iteration over non-sequence
How can I fix this?

Edited by cruze098

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Gribouillis
0

At line 18, you're passing a Coumpound instance to items_string(). You should probably pass self.items_list. Otherwise, it's always better to post full traceback (in a code box).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.