tags:

views:

75

answers:

1

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!

+1  A: 

The output contains results from every row because you are printing the 1st and 9th columns for every row.

row1[0] is out of range for whatever row that is because there aren't any items on that particular line of the file. You can't access the first item in row1 if row1 doesn't have any items to access. Check row1 on each loop to see if it has anything in it.

Daniel DiPaolo
oh that makes sense geez sorry again that's what I get for trying to do this at 4 on Friday, I should go update my tasks and call it a day, thanks
KacieHouser