Guys I'm still confusing my script is working better, but not enough. I did a logfile to see which products are not found anymore in the CSV and I found some that are present but python says they are not ??
Here is the product in the CSV: MONIIE2407HDS-B1;MON;II;E2407HDS-B1;E2407HDS-B1;IIYAMA LCD 24" Wide 1920x1080TN Speakers 2ms Black DVI HDMI;133;20;RECTD0.41;0,41;;;;;;;;; Here is what python reports: e2208hds-b2, 721 not found e2273hds-b1, 722 not found e2274hds-b2, 723 not found e2407hds-b1, 724 not found And here is my final code: ( I hope it look better now :) ) def Change_price(): # Changes the price in the DB if the price in the CSV is changed TotalUpdated = 0 # Counter for total updated TotalSKUFound = 0 # Total SKU from the DB coresponds to the one in the CSV TotalSKUinDB = 0 # Total SKU in the DB for row in PRODUCTSDB: TotalSKUinDB +=1 db_sku = row["sku"].lower() db_price = float(row["price"]) found = False try: for x in pricelist: try: csv_price = x[6] csv_price = csv_price.replace(",",".") csv_price = float(csv_price) csv_new_price = csv_price*1.10 csv_sku = x[4].lower() csv_stock = int(x[7]) # I used this as normally I used stock in the condition match = re.search(db_sku, csv_sku) if len(db_sku) != 0 and match: TotalSKUFound +=1 if csv_new_price < db_price and csv_stock > 0: print db_sku, csv_price, db_price, csv_new_price Update_SQL(csv_new_price, db_sku) TotalUpdated += 1 found = True except IndexError: # I have a lot of index error in the CSV (empty fields) and the loop gives "index error" I don't care about them pass except ValueError: pass except TypeError: pass except IndexError: pass if not found: WriteLog(db_sku, db_sku,) TotalNotFound = TotalSKUinDB - TotalSKUFound print "Total SKU in the DB %s" % TotalSKUinDB print "Total SKU coresponds to the DB and CSV %s" % TotalSKUFound print "Total updated: %s" % TotalUpdated print"Total not found with in the distributor: %s" % TotalNotFound -- http://mail.python.org/mailman/listinfo/python-list