On Apr 9, 5:39 pm, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote: > > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:python- > > [EMAIL PROTECTED] On Behalf Of jeffself > > Sent: Wednesday, April 09, 2008 5:11 PM > > To: [EMAIL PROTECTED] > > Subject: How can I use quotes without escaping them using CSV? > > > If I put an escape character in, it works. For example, if I use ~ as > > my escape character, my output looks like this: > > 0001[tab]Michael L. ~"Mick~" Jones[tab]189 > > > I don't want that. If I don't include an escape character, it doesn't > > work. > > > Here's my code: > > import sys > > import csv > > from readexcel import * > > > f = open("results.txt", 'wb') > > book = sys.argv[1] > > sheet = sys.argv[2] > > > xl = readexcel(book) > > sheetnames = xl.worksheets() > > > for s in sheetnames: > > if s == sheet: > > writer = csv.writer(f, delimiter='\t', quoting=csv.QUOTE_NONE) > > for row in xl.getiter(s): > > writer.writerow((row['Precinct'],row['Candidate'],unicode(int(row['Vote > > > s'])))) > > f.close() > > The documentation is pretty, uhm, obtuse, but you also need to set > quotechar. > > import sys > import csv > > names = ['Michael L. "Mick" Jones', 'Vickie A. Meyers', 'John "Jack" > Smith'] > > writer = csv.writer(sys.stdout, delimiter='\t', quotechar='', > quoting=csv.QUOTE_NONE) > for i in names: > writer.writerow(['a', i, 'b']) > > output: > a Michael L. "Mick" Jones b > a Vickie A. Meyers b > a John "Jack" Smith b > > ***** > > 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. GA621
I set quotechar="" and was able to get it to work. I'll try this at work tomorrow! -- http://mail.python.org/mailman/listinfo/python-list