> -----Original Message----- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Mike P > Sent: Monday, February 11, 2008 11:42 AM > To: python-list@python.org > Subject: Re: CSV Reader > > Cheers for the help, the second way looked to be the best in the end, > and thanks for the boolean idea > > Mike > > > > working_CSV = "//filer/common/technical/Research/E2C/Template_CSV/ > DFAExposureToConversionQueryTool.csv" > > save_file = open("//filer/common/technical/Research/E2C/Template_CSV/ > CSV_Data2.csv","w") > > CSV_Data = open(working_CSV) > data = CSV_Data.readlines() > flag=False > for record in data: > if record.startswith('"Transaction ID"'): > flag=True > if flag: > save_file.write(record) > save_file.close()
Don't be a pansy. Use the csv module, or add a check for record.startswith('TransactionID'). There's no guarantee that csv columns will be double-quoted. (Leading whitespace may or may not be acceptable, too.) Look at the first piece of sample code in the documentation for the csv module. (Section 9.1.5 in python 2.5) You're 99% of the way to using csv.reader() properly. Nitpick: If the boolean check is expensive, then if not flag and record.startswith(...): flag = true Nitpick: flag is a weak name. Use something like bPrint, okay2print, or print_now or anything that's more descriptive. In larger and/or more complex programs, meaningful variable names are a must. ***** The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. GA622 -- http://mail.python.org/mailman/listinfo/python-list