: : : : :Hi,Thanks for your reply,The data is a pricelist in excel,with columns for decsciption, price,tax, etc(7 items in all) with headings for each item.I can't figure out how to list all the lines from one heading to the next?It must be easy but I cannot see it!
: : :
: : : Sorry if I sound dense, but I'm having a hard time picturing what you're trying to do.
: : :
: : :
: : :Hi Infidel,I'm obviously not describing my problem very well so I'll try from a different angle.How do I read specific rows from data in an Excel spreadsheet.I have tried variations of this:
: :
: : file=open("/home/pricelist.csv","r")
: : line=(file.readlines())
: : file.close
: : rows=len(line)
: : list=[]
: : print rows
: : for count in range(1,rows):
: : myline=line[count]
: : splitline=re.split('","|\n',myline)
: : if splitline[0]=='CD/CDRW/DVD Drive':
: : print myline
: : list.append(count)
: : if splitline[0]=='Computer Cases':
: : print myline
: : list.append(count)
: : print list
: : Then I need to list all rows between these two headings.Am I doing this right?Sorry I've taken up so much of your time but thanks for your help
:
: Ah, ok. I didn't know what CSV files were so I made up a simple on in Excel to see what they look like. I'm with you now. Here is my script which reads the contents of a csv file, and prints out all the lines from the one that starts with 'CD/CDRW/DVD Drive' through the one that starts with 'Computer Cases':
:
:
: lines = open("K:\\EXCEL\\Book1.csv","r").read().split("\n")
: output = False
: for line in lines:
: if line.find("CD/CDRW/DVD Drive") == 0:
: output = True
: elif line.find("Computer Cases") == 0:
: print line
: break
: if output: print line
:
:
: Notice that you're making things more difficult than they need to be. Python is quite intelligent in its syntax. You can iterate through a list without ever using an index.
:
Hi Infidel,I want to thank you for your patience with me,I would not have thought of that solution.I will not bother you for a while as I try and expand what youhave shown me,I appreciate more than I can put into words people like you who are willing to spend their time helping others come to grips with what can be a daunting challenge.thanks
:
:
nevle