and which method is the best, Daniel's generator or the subclass?
--
http://mail.python.org/mailman/listinfo/python-list
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,
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
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
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
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
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
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
>
>> 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:
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(
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
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
12 matches
Mail list logo