Re: CSV with comments

2006-07-20 Thread GinTon
and which method is the best, Daniel's generator or the subclass? -- http://mail.python.org/mailman/listinfo/python-list

Re: CSV with comments

2006-07-19 Thread Daniel Dittmar
Sion Arrowsmith wrote: > Daniel Dittmar <[EMAIL PROTECTED]> wrote: >> if line [:1] == '#': > > What's wrong with line[0] == '#' ? (For one thing, it's fractionally > faster than [:1].) > Matter of taste. Occasionally, I use line iterators that strip the '\n' from the end of each line,

Re: CSV with comments

2006-07-19 Thread Steve Holden
Sion Arrowsmith wrote: > Daniel Dittmar <[EMAIL PROTECTED]> wrote: > >>if line [:1] == '#': > > > What's wrong with line[0] == '#' ? (For one thing, it's fractionally > faster than [:1].) > > For that matter, what's wrong with line.startswith('#') which expresses the intent rat

Re: CSV with comments

2006-07-19 Thread Duncan Booth
Sion Arrowsmith wrote: > Daniel Dittmar <[EMAIL PROTECTED]> wrote: >> if line [:1] == '#': > > What's wrong with line[0] == '#' ? (For one thing, it's fractionally > faster than [:1].) > line[0] assumes that the line isn't blank. If the input iterator is a file then that will hold true

Re: CSV with comments

2006-07-19 Thread Sion Arrowsmith
Daniel Dittmar <[EMAIL PROTECTED]> wrote: > if line [:1] == '#': What's wrong with line[0] == '#' ? (For one thing, it's fractionally faster than [:1].) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | "Frankly I have no feelings towards penguins one way or the oth

Re: CSV with comments

2006-07-18 Thread skip
Whoops, missed the second part. John> Is there any reason to prefer this approach to Daniel's, apart John> from being stuck with an older (pre-yield) version of Python? No, it's just what I came up with off the top of my head. John> A file given to csv.reader is supposed to be opened

Re: CSV with comments

2006-07-18 Thread skip
John> This is recursive. Unlikely of course, but if the file contained a John> large number of empty lines, might this not cause the recursion John> limit to be exceeded? Sure, but I was lazy. ;-) Skip -- http://mail.python.org/mailman/listinfo/python-list

Re: CSV with comments

2006-07-18 Thread John Machin
On 19/07/2006 5:34 AM, [EMAIL PROTECTED] wrote: > >> In csv.reader, is there any way of skip lines that start whith '#' or > >> empty lines > > Nope. When we wrote the module we weren't aware of any "spec" that > specified comments or blank lines. You can easily write a file wrapper to >

Re: CSV with comments

2006-07-18 Thread skip
>> In csv.reader, is there any way of skip lines that start whith '#' or >> empty lines Nope. When we wrote the module we weren't aware of any "spec" that specified comments or blank lines. You can easily write a file wrapper to filter them out though: class BlankCommentCSVFile:

Re: CSV with comments

2006-07-18 Thread Daniel Dittmar
GinTon wrote: > GinTon wrote: >> In csv.reader, is there any way of skip lines that start whith '#' or >> empty lines >> I would add comments at my CSV file > > For skip comment I get a dirty trick: > > reader = csv.reader(open(csv_file)) > for csv_line in reader: > if csv_line[0].startswith(

Re: CSV with comments

2006-07-18 Thread GinTon
GinTon wrote: > In csv.reader, is there any way of skip lines that start whith '#' or > empty lines > I would add comments at my CSV file For skip comment I get a dirty trick: reader = csv.reader(open(csv_file)) for csv_line in reader: if csv_line[0].startswith('#'): continue But no

CSV with comments

2006-07-18 Thread GinTon
In csv.reader, is there any way of skip lines that start whith '#' or empty lines I would add comments at my CSV file -- http://mail.python.org/mailman/listinfo/python-list