Python csv reader acting weird
        Posted  
        
            by PylonsN00b
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by PylonsN00b
        
        
        
        Published on 2010-05-21T21:15:49Z
        Indexed on 
            2010/05/21
            21:20 UTC
        
        
        Read the original article
        Hit count: 366
        
So OK if I run this wrong code:
csvReader1 = csv.reader(file('new_categories.csv', "rU"), delimiter=',')
for row1 in csvReader1:
    print row1[0]
    print row1[8]
    category_sku = str(row[8])
    if category_sku == sku:
        classifications["Craft"] = row[0]
        classifications["Theme"] = row[1]
I get:
    Knitting
    391
    Traceback (most recent call last):
      File "upload_all_inventory_ebay.py", line 403, in <module>
        inventory_item_list = get_item_list(product)
      File "upload_all_inventory_ebay.py", line 294, in get_item_list
        category_sku = str(row[8])
    NameError: global name 'row' is not defined
Where Knitting and 391 are exactly right, of course I need to refer to row[8] as row1[8]...k so I do this:
    csvReader1 = csv.reader(file('new_categories.csv', "rU"), delimiter=',')
    for row1 in csvReader1:
        print row1[0]
        print row1[8]
        category_sku = str(row1[8])
        if category_sku == sku:
            classifications["Craft"] = row1[0]
            classifications["Theme"] = row1[1]
And I get this:
...........
Crochet
107452
Knitting
107454
Knitting
107455
Knitting
107456
Knitting
107457
Crochet
108200
Crochet
108201
Crochet
108205
Crochet
108213
Crochet
108214
Crochet
108217
108432
Quilt
108451
108482
108488
Scrapbooking
108711
Knitting
122363
Needlework
Beading
Crafts & Decorating
Crochet
Crochet
Crochet
Traceback (most recent call last):
  File "upload_all_inventory_ebay.py", line 403, in <module>
    inventory_item_list = get_item_list(product)
  File "upload_all_inventory_ebay.py", line 292, in get_item_list
    print row1[0]
IndexError: list index out of range
Where the output you see there is every effing thing in column 0 and column 1 !!!!!!!!!! Why? And WHY is row1[0] out of range if it wasn't before. YAY Fridays!
© Stack Overflow or respective owner