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

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
like quotes (needest at start and end) but not trying to hit things in one go. Better to match exactly the special case you expect and then scour of mismatches than to incorrectly match and have that mistake buried in the data. (I think I have the re syntax approximately right.) The csv

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

CSV reader ignore brackets

2019-09-24 Thread Mihir Kothari
Hi Team, I am using python 3.4. I have a CSV file as below: ABC,PQR,(TEST1,TEST2) FQW,RTE,MDE Basically comma-separated rows, where some rows have a data in column which is array like i.e. in brackets. So I need to read the file and treat such columns as one i.e. do not separate based on comma i

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread rusi
On Jan 30, 10:35 pm, rusi wrote: > On Jan 30, 6:31 pm, bansi wrote: > > Isn't it possible to implement your suggestion without installing > > Visual C++ 2008 . > > http://code.google.com/p/pyodbc/wiki/Building#Windows Well... This is what the official site says... On second thoughts I wonder: Wo

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread rusi
On Jan 30, 6:31 pm, bansi wrote: > On Jan 28, 4:22 pm, Benjamin Kaplan wrote: > > > You'll need to have Visual C++ 2008 (not 2010) installed for this to > > work. You can get it for free > > fromhttp://www.microsoft.com/express/Downloads/if > > you don't already have it. > > > Thanks Benjamin. W

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-30 Thread bansi
6, 8:31 pm, MRAB wrote: > > >> >> > On 27/01/2011 00:57, bansi wrote: > > >> >> > > On Jan 26, 6:25 pm, Ethan Furman  wrote: > >> >> > >> bansi wrote: > > >> >> > >>   >  First namelookupWrapper.py run

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-28 Thread Benjamin Kaplan
00:57, bansi wrote: >> >> >> > > On Jan 26, 6:25 pm, Ethan Furman  wrote: >> >> > >> bansi wrote: >> >> >> > >>   >  First namelookupWrapper.py running under Python 2.6 accept >> >> > >> arguments >&

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-28 Thread bansi
6:25 pm, Ethan Furman  wrote: > >> > >> bansi wrote: > > >> > >>   >  First namelookupWrapper.py running under Python 2.6 accept > >> > >> arguments > >> > >>   >  from stdin and uses csv reader object to read it i.e. &

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-28 Thread Benjamin Kaplan
gt; > >> bansi wrote: >> >> > >>   >  First namelookupWrapper.py running under Python 2.6 accept >> > >> arguments >> > >>   >  from stdin and uses csv reader object to read it i.e. >> > >>   >  r=csv.reader(sys.s

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-28 Thread bansi
nning under Python 2.6 accept arguments > > >>   >  from stdin and uses csv reader object to read it i.e. > > >>   >  r=csv.reader(sys.stdin) > > > >>   >  And then it has to pass csv reader object to another python script > > >>   >

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-28 Thread bansi
On Jan 26, 8:31 pm, MRAB wrote: > On 27/01/2011 00:57, bansi wrote: > > > > > > > On Jan 26, 6:25 pm, Ethan Furman  wrote: > >> bansi wrote: > > >>   >  First namelookupWrapper.py running under Python 2.6 accept arguments > >>   >  from

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread MRAB
On 27/01/2011 00:57, bansi wrote: On Jan 26, 6:25 pm, Ethan Furman wrote: bansi wrote: > First namelookupWrapper.py running under Python 2.6 accept arguments > from stdin and uses csv reader object to read it i.e. > r=csv.reader(sys.stdin) > > And then it has to

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread bansi
On Jan 26, 6:25 pm, Ethan Furman wrote: > bansi wrote: > >  > First namelookupWrapper.py running under Python 2.6 accept arguments >  > from stdin and uses csv reader object to read it i.e. >  > r=csv.reader(sys.stdin) >  > >  > And then it has to pass csv re

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread Ethan Furman
bansi wrote: > First namelookupWrapper.py running under Python 2.6 accept arguments > from stdin and uses csv reader object to read it i.e. > r=csv.reader(sys.stdin) > > And then it has to pass csv reader object to another python script > namelookup.py running under Python 2

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread bansi
them that way, though? What constraint is > keeping you from doing the work in a single process, where the CSV > reader object can be shared? > > > If thats not possible then please let me know how to do the workaround > > i didnt understood the import thing and not sure if i

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread Ben Finney
work in a single process, where the CSV reader object can be shared? > If thats not possible then please let me know how to do the workaround > i didnt understood the import thing and not sure if it helps in my > case The problem as you've described it so far is best solved by

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread bansi
" from > > CLI and has following code snippet > > > idf = sys.argv[1] > > namef = sys.argv[2] > > real_script = "C:\\Splunk\\etc\\apps\\search\\bin\\namelookup.py" > > r = csv.reader(sys.stdin) > > os.execv(python_executable, [ python_executable, real_

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread Chris Rebert
sys.argv[1] > namef = sys.argv[2] > real_script = "C:\\Splunk\\etc\\apps\\search\\bin\\namelookup.py" > r = csv.reader(sys.stdin) > os.execv(python_executable, [ python_executable, real_script ] + > sys.argv[1:] ) > > Wondering how would i pass csv reader object &qu

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread bansi
quot;memberName" from > > CLI and has following code snippet > > > idf = sys.argv[1] > > namef = sys.argv[2] > > real_script = "C:\\Splunk\\etc\\apps\\search\\bin\\namelookup.py" > > r = csv.reader(sys.stdin) > > os.execv(python_executable, [

Re: Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread Emile van Sebille
uot;C:\\Splunk\\etc\\apps\\search\\bin\\namelookup.py" r = csv.reader(sys.stdin) os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:] ) Wondering how would i pass csv reader object "r" as an argument using os.execv() to another python script i.e. namelookup.p

Is it possible to pass CSV Reader Object As Argument to another Python File ??? Options

2011-01-26 Thread Bansilal Haudakari
lookup.py" r = csv.reader(sys.stdin) os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:] ) Wondering how would i pass csv reader object "r" as an argument using os.execv() to another python script i.e. namelookup.py Regards, Bansi --

Is it possible to pass CSV Reader Object As Argument to another Python File ???

2011-01-26 Thread bansi
ch\\bin\\namelookup.py" r = csv.reader(sys.stdin) os.execv(python_executable, [ python_executable, real_script ] + sys.argv[1:] ) Wondering how would i pass csv reader object "r" as an argument using os.execv() to another python script i.e. namelookup.py -- http://mail.python.org/mailman/listinfo/python-list

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

csv reader

2009-12-15 Thread Emmanuel
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='test' a=csv.reader(open(arquivoCSV),delimiter=',') tab=[] for row

Re: intermediate python csv reader/writer question from a beginner

2009-02-24 Thread Nick Craig-Wood
Learning Python wrote: > anything related to csv, I usually use VB within excel to manipulate > the data, nonetheless, i finally got the courage to take a dive into > python. i have viewed a lot of googled csv tutorials, but none of > them address everything i need. Nonetheless, I was wonder

Re: intermediate python csv reader/writer question from a beginner

2009-02-23 Thread Chris Rebert
On Mon, Feb 23, 2009 at 1:33 PM, Learning Python wrote: > anything related to csv, I usually use VB within excel to manipulate > the data, nonetheless, i finally got the courage to take a dive into > python. i have viewed a lot of googled csv tutorials, but none of > them address everything i nee

intermediate python csv reader/writer question from a beginner

2009-02-23 Thread Learning Python
anything related to csv, I usually use VB within excel to manipulate the data, nonetheless, i finally got the courage to take a dive into python. i have viewed a lot of googled csv tutorials, but none of them address everything i need. Nonetheless, I was wondering if someone can help me manipulat

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

CSV reader and unique ids

2008-09-01 Thread Mike P
Hi All, 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, can anyone advise? Below is the code so far fin = open(CSV_INPUT, "rb") fout = open(CSV_OUTPUT, "wb") reader = c

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
\pythonwin\pywin\framework > \scriptutils.py", line 310, in RunScript > exec codeObject in __main__.__dict__ > File "Y:\technical\Research\E2C\Template_CSV\import CSV test.py", > line 10, in > if not start_line and row.startswith('Transaction ID'): >

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
/Research/E2C/Template_CSV/ > DFAExposureToConversionQueryTool.csv" > > save_file = "//filer/common/technical/Research/E2C/Template_CSV/ > CSV_Data2.csv" > > start_line=False > import csv > reader = csv.reader(open(working_CSV, "rb")

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
te_CSV/ CSV_Data2.csv" start_line=False import csv reader = csv.reader(open(working_CSV, "rb")) writer = csv.writer(open(save_file, "wb")) for row in reader: if not start_line and record.startswith("'Transaction ID'"): start_line=True

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", > &g

CSV Reader

2008-02-11 Thread Mike P
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 lines of below..

Re: High level csv reader

2006-11-01 Thread George Sakkis
[EMAIL PROTECTED] wrote: > George> It occured to me that most times I read a csv file, I'm often > George> doing from scratch things like assigning labels to columns, > George> mapping fields to the appropriate type, ignoring some fields, > George> changing their order, etc. Before I

Re: High level csv reader

2006-11-01 Thread skip
George> It occured to me that most times I read a csv file, I'm often George> doing from scratch things like assigning labels to columns, George> mapping fields to the appropriate type, ignoring some fields, George> changing their order, etc. Before I go on and reinvent the Ge

Re: High level csv reader

2006-11-01 Thread John Machin
George Sakkis wrote: > It occured to me that most times I read a csv file, I'm often doing > from scratch things like assigning labels to columns, mapping fields to > the appropriate type, ignoring some fields, changing their order, etc. > Before I go on and reinvent the wheel, is there a generic h

Re: High level csv reader

2006-11-01 Thread John Machin
James Stroud wrote: > George Sakkis wrote: > > It occured to me that most times I read a csv file, I'm often doing > > from scratch things like assigning labels to columns, mapping fields to > > the appropriate type, ignoring some fields, changing their order, etc. > > Before I go on and reinvent

Re: High level csv reader

2006-11-01 Thread Fredrik Lundh
James Stroud wrote: >> Before I go on and reinvent the wheel, is there a generic high level >> wrapper around csv.reader that does all this ? > > There is a csv in the standard library. I'm not sure the "csv" module qualifies as a high-level wrapper around itself, though. -- http://mail.pyt

Re: High level csv reader

2006-11-01 Thread James Stroud
George Sakkis wrote: > It occured to me that most times I read a csv file, I'm often doing > from scratch things like assigning labels to columns, mapping fields to > the appropriate type, ignoring some fields, changing their order, etc. > Before I go on and reinvent the wheel, is there a generic h

High level csv reader

2006-10-31 Thread George Sakkis
It occured to me that most times I read a csv file, I'm often doing from scratch things like assigning labels to columns, mapping fields to the appropriate type, ignoring some fields, changing their order, etc. Before I go on and reinvent the wheel, is there a generic high level wrapper around csv.

Re: Python's CSV reader

2005-08-08 Thread Peter Otten
Stephan wrote: > DictReader field names on the fly. Here is a rudimentary example of my > working code and the data it can parse. > > - > John|Smith > Beef|Potatos|Dinner Roll|Ice Cream > Susan|Jones > Chicken|Peas|Biscuits|Cake > Roger|Miller > Pork|Salad|Muf

Re: Python's CSV reader

2005-08-07 Thread Stephan
Andrew McLean wrote: > You are welcome. One point. I think there have been at least two > different interpretations of precisely what you task is. > > I had assumed that all the different "header" lines contained data for > the same fields in the same order, and similarly that all the "detail" > l

Re: Python's CSV reader

2005-08-05 Thread Andrew McLean
In article <[EMAIL PROTECTED]>, Stephan <[EMAIL PROTECTED]> writes >Thank you all for these interesting examples and methods! You are welcome. One point. I think there have been at least two different interpretations of precisely what you task is. I had assumed that all the different "header" l

Re: Python's CSV reader

2005-08-04 Thread Peter Otten
Stephan wrote: > Thank you all for these interesting examples and methods! You're welcome. > Supposing I want to use DictReader to bring in the CSV lines and tie > them to field names, (again, with alternating lines having different > fields), should I use two two DictReaders as in Christopher's

Re: Python's CSV reader

2005-08-04 Thread Stephan
Thank you all for these interesting examples and methods! Supposing I want to use DictReader to bring in the CSV lines and tie them to field names, (again, with alternating lines having different fields), should I use two two DictReaders as in Christopher's example or is there a better way? -- St

Re: Python's CSV reader

2005-08-04 Thread Andrew McLean
am I >better off using read and split? > >Thanks for your insight, >Stephan > The csv module should be suitable. The reader just takes each line, parses it, then returns a list of strings. It doesn't matter if different lines have different numbers of fields. To get an idea

Re: Python's CSV reader

2005-08-04 Thread Peter Otten
Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Yes, it can: import csv import sys reader = csv.reader(sys.stdin) while True: try: names = reader.next() values = reader.next() except StopIteratio

Re: Python's CSV reader

2005-08-03 Thread Christopher Subich
Stephan wrote: > Can the CSV module be coerced to read two line formats at once or am I > better off using read and split? Well, readlines/split really isn't bad. So long as the file fits comfortably in memory: fi = open(file) lines = fi.readlines() evens = iter(lines[0::2]) odds = iter(lines[1

Python's CSV reader

2005-08-03 Thread Stephan
I'm fairly new to python and am working on parsing some delimited text files. I noticed that there's a nice CSV reading/writing module included in the libraries. My data files however, are odd in that they are composed of lines with alternating formats. (Essentially the rows are a header record a