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

Ian Bicking ianb at colorstudy.com
Sat Dec 1 23:06:36 CET 2007

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 

One thing I've noticed is that some string operations are fairly 
efficient in this case, because they notice when they wouldn't do 
anything and don't create a new string.

First, to make sure it's a string that doesn't get intern'd or anything 
(I think, maybe, some small strings get reused):

   >>> x = 'x'*1000

Now, .replace() works nicely:

   >>> x.replace('&', '&') is x
   >>> x.replace('x', 'y') is x

Concatenation also works:

   >>> x + '' is x

But not split:

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

Ian Bicking : ianb at colorstudy.com : http://blog.ianbicking.org

More information about the Chicago mailing list