Re: CSV reader ignore brackets

2019-09-26 Thread Piet van Oostrum
Skip Montanaro writes: > How about just replacing *\(([^)]*)\)* with *"\1"* in a wrapper class's > line reading method? (I think I have the re syntax approximately right.) > The csv reader will "just work". Again, nesting parens not allowed. > > Skip here is some working code: def PReader(csvfi

Re: CSV reader ignore brackets

2019-09-25 Thread Skip Montanaro
> Besides, the point isn't the shortest code but to illustrate the idea > of handling special syntax. In my defense, I was typing on my phone while watching a show on Netflix. I was hardly in a position to test any code. :-) As you indicated though, the problem is under-specified (nesting?, pres

Re: CSV reader ignore brackets

2019-09-24 Thread Cameron Simpson
On 24Sep2019 19:02, Skip Montanaro wrote: How about just replacing *\(([^)]*)\)* with *"\1"* in a wrapper class's line reading method? Will that work if the OP's (TEST1,TEST2) term itself contains quotes? Not that his example data did, but example data are usually incomplete :-) Also, tha

Re: CSV reader ignore brackets

2019-09-24 Thread Skip Montanaro
How about just replacing *\(([^)]*)\)* with *"\1"* in a wrapper class's line reading method? (I think I have the re syntax approximately right.) The csv reader will "just work". Again, nesting parens not allowed. Skip -- https://mail.python.org/mailman/listinfo/python-list

Re: CSV reader ignore brackets

2019-09-24 Thread MRAB
On 2019-09-25 00:09, Cameron Simpson wrote: On 24Sep2019 15:55, Mihir Kothari wrote: I am using python 3.4. I have a CSV file as below: ABC,PQR,(TEST1,TEST2) FQW,RTE,MDE Really? No quotes around the (TEST1,TEST2) column value? I would have said this is invalid data, but that does not help yo

Re: CSV reader ignore brackets

2019-09-24 Thread Cameron Simpson
On 24Sep2019 15:55, Mihir Kothari wrote: I am using python 3.4. I have a CSV file as below: ABC,PQR,(TEST1,TEST2) FQW,RTE,MDE Really? No quotes around the (TEST1,TEST2) column value? I would have said this is invalid data, but that does not help you. Basically comma-separated rows, where

Re: csv reader

2009-12-17 Thread Emmanuel
As csv.reader does not suport utf-8 encoded files, I'm using: fp = codecs.open(arquivoCSV, "r", "utf-8") self.tab=[] for l in fp: l=l.replace('\"','').strip() self.tab.append(l.split(',')) It works much better except that when I do self.sel.type("q", ustring) where ustring is a unicode st

Re: csv reader

2009-12-15 Thread Gabriel Genellina
En Tue, 15 Dec 2009 19:12:01 -0300, Emmanuel escribió: Then my problem is diferent! In fact I'm reading a csv file saved from openoffice oocalc using UTF-8 encoding. I get a list of list (let's cal it tab) with the csv data. If I do: print tab[2][4] In ipython, I get: equação de Toricelli. Ta

Re: csv reader

2009-12-15 Thread Emmanuel
Then my problem is diferent! In fact I'm reading a csv file saved from openoffice oocalc using UTF-8 encoding. I get a list of list (let's cal it tab) with the csv data. If I do: print tab[2][4] In ipython, I get: equação de Toricelli. Tarefa exercícios PVR 1 e 2 ; PVP 1 If I only do: tab[2][4]

Re: csv reader

2009-12-15 Thread Jerry Hill
On Tue, Dec 15, 2009 at 4:24 PM, Emmanuel wrote: > I have a problem with csv.reader from the library csv. I'm not able to > import accentuated caracters. For example, I'm trying to import a > simple file containing a single word "equação" using the following > code: > > import csv > arquivoCSV='te

Re: csv reader

2009-12-15 Thread Chris Rebert
On Tue, Dec 15, 2009 at 1:24 PM, Emmanuel wrote: > I have a problem with csv.reader from the library csv. I'm not able to > import accentuated caracters. For example, I'm trying to import a > simple file containing a single word "equação" using the following > code: > > import csv > arquivoCSV='te

Re: CSV reader and unique ids

2008-09-01 Thread Tim Golden
Mike P wrote: I'm trying to use the CSV module to read in some data and then use a hashable method (as there are millions of records) to find unique ids and push these out to another file, You could either zip with a counter or use the uuid module, depending on just how unique you want your ids

RE: CSV Reader

2008-02-12 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Mike P > Sent: Tuesday, February 12, 2008 5:37 AM > To: python-list@python.org > Subject: Re: CSV Reader > > just saw i needed to change record.startswith to row.st

Re: CSV Reader

2008-02-12 Thread Gabriel Genellina
En Tue, 12 Feb 2008 08:37:13 -0200, Mike P <[EMAIL PROTECTED]> escribi�: > just saw i needed to change record.startswith to row.startswith > but i get hte following traceback error > > Traceback (most recent call last): > File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework > \scriptu

Re: CSV Reader

2008-02-12 Thread Mike P
I was just trying to do it with the CSV module -- http://mail.python.org/mailman/listinfo/python-list

Re: CSV Reader

2008-02-12 Thread Mike P
Hi Chris that's exactley what i wanted to do, Many thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: CSV Reader

2008-02-12 Thread Chris
On Feb 12, 12:21 pm, Mike P <[EMAIL PROTECTED]> wrote: > I did just try to post, but it doesn't look like it has appeared? > > I've used your advice Andrew and tried to use the CSV module, but now > it doesn't seem to pick up the startswith command? > Is this because of the way the CSV module is re

Re: CSV Reader

2008-02-12 Thread Mike P
just saw i needed to change record.startswith to row.startswith but i get hte following traceback error Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework \scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "Y:\te

Re: CSV Reader

2008-02-12 Thread Mike P
I did just try to post, but it doesn't look like it has appeared? I've used your advice Andrew and tried to use the CSV module, but now it doesn't seem to pick up the startswith command? Is this because of the way the CSV module is reading the data in? I've looked into the module description but i

Re: CSV Reader

2008-02-11 Thread Gabriel Genellina
En Mon, 11 Feb 2008 14:41:54 -0200, Mike P <[EMAIL PROTECTED]> escribi�: > CSV_Data = open(working_CSV) > data = CSV_Data.readlines() > flag=False > for record in data: > if record.startswith('"Transaction ID"'): > [...] Files are already iterable by lines. There is no need to use readl

RE: CSV Reader

2008-02-11 Thread Reedick, Andrew
> -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

Re: CSV Reader

2008-02-11 Thread Mike P
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.c

RE: CSV Reader

2008-02-11 Thread Reedick, Andrew
> -Original Message- > From: [EMAIL PROTECTED] [mailto:python- > [EMAIL PROTECTED] On Behalf Of Mike P > Sent: Monday, February 11, 2008 11:10 AM > To: python-list@python.org > Subject: Re: CSV Reader > > Hi Larry, > > i'm still getting to grips wit

Re: CSV Reader

2008-02-11 Thread Mike P
Hi Larry, i'm still getting to grips with python, but rest assured i thinkn it's better for me to write hte code for learnign purposes My basic file is here, it comes up with a syntax error on the startswith line, is this because it is potentially a list? My idea was to get the lines number where

Re: CSV Reader

2008-02-11 Thread Larry Bates
Mike P wrote: > Hi All, > > I want to read in a CSV file, but then write out a new CSV file from a > given line.. > > I'm using the CSV reader and have the the line where i want to start > writing the new file from begins with > "Transaction ID", > > i thought it should be something along the li