[Python-3000] Automatically invoking str() in str.join()

Jack Diederich jack at performancedrivers.com
Thu Apr 27 21:19:00 CEST 2006


On Thu, Apr 27, 2006 at 10:18:23AM -0700, Alex Martelli wrote:
> On 4/27/06, Barry Warsaw <barry at python.org> wrote:
> > On Thu, 2006-04-27 at 10:08 -0700, Aahz wrote:
> >
> > > While I hate the way it looks, I never have gotten mixed up about the
> > > order of arguments since switching to ''.join(l).
> >
> > Which is why
> >
> > EMPTYSTRING = ''
> >
> > ...
> >
> > EMPTYSTRING.join(seq)
> >
> > looks much better.  But hey, yeah, a join() builtin would be fine if it
> > took the string arg first, so that
> >
> > ''.join(seq) == join('', seq)
> 
> I think I would prefer a signature of:
>     join(seq, joiner='')
> 
> Rationale: an emptystring joiner is the most frequent cases, but
> several others (space, newline, space-comma, ...) occur often enough
> to be worth allowing the joiner to be optionally specified.

Grepping through my own for joins that use a literal:

Join type   Count
-------------------
','.join    83
''.join     61  # the default suggested above
str.join    35
' '.join    28
string.join 10
OTHER.join  45  # everything else with a literal ' AND '.join, etc

So I'd prefer if the seperator was explicit and up front where
I can see it instead of hiding at the end.

Also, if join() is builtin does that mean split() will be too?

-Jack


More information about the Python-3000 mailing list