# -*- coding: utf-8 -*- import csv rawdat = open('QBITEMS.IIF') csvdat = csv.reader(rawdat, dialect='excel-tab') spstrdes = " " spstrupc = " " spstrcsh = " " def putitin(it, into, where = 1): if len(it) < len(into): #appends it onto into, when it can fit in into if where == 1: new = into[:-len(it)] + it else: new = it + into[:-len(it)] elif len(it) > len(into): #cuts it down to len into, when it can't fit in into. new = it[:len(into)] else: new = it return new qbi = [] for row in csvdat: if row[0] == "INVITEM": print(row) qbi.append(putitin(row[5],spstrdes,0) + " " + putitin(row[1],spstrupc,0) + " " + putitin(row[12],spstrcsh) + " " + putitin(row[13],spstrcsh)) # 5 is Description # 1 is UPC code # 12, 13 sales price/our price elif row[0] == "!ENDASSEMBLY": break result = open('qbitems.qbi', 'w+t') result.write("\n".join(qbi)) print("Success!!!") # TODOS # write list qbi to file CHECK # more reliable file interface MAYBE LATER