[Chicago] is there really no built-in file/iter split() thing?

Damien Grassart damien at grassart.com
Sun Dec 2 01:55:48 CET 2007


On 12/1/07, Ian Bicking <ianb at colorstudy.com> wrote:
>
> Not particularly apropos of the discussion, but I thought about split,
> and whether it is advantageous to do:
>
>    if ';' in line:
>        parts = line.split(';')
>
> Assuming that most lines won't have ; in them.  "';' in line" is fairly
> fast.


Good point. Running a quick test on a 10 million line file, that check added
about a 10% overhead when every single line performed a split, but it made
it nearly twice as fast when only 1 in 3 lines needed it.


>    >>> x.split()[0] is x
>    False


I assume it was done that way because split() returns a different type than
it's object, so it's not as easy as "if (no_work_needed) return self;".
Granted it shouldn't be that much harder either, but I I'm just guessing
anyways. ;)

-Damien
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/chicago/attachments/20071202/34129055/attachment.htm 


More information about the Chicago mailing list