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
> 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
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
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
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
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
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
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
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
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
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
>&
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.
&
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
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
> > >> >
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
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
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
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
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
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
" 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_
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
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, [
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
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
--
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
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
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
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]
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
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
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
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
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
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
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
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
> -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
\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'):
>
I was just trying to do it with the CSV module
--
http://mail.python.org/mailman/listinfo/python-list
Hi Chris that's exactley what i wanted to do,
Many thanks
--
http://mail.python.org/mailman/listinfo/python-list
/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")
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
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
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
> -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
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
> -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
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
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
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..
[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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
67 matches
Mail list logo