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

Crutcher Dunnavant crutcher at gmail.com
Fri Apr 28 05:50:42 CEST 2006


On 4/27/06, Alex Martelli <aleaxit at gmail.com> 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='')

Just because I have to, why not consider a join operator?

Lets look at a simple case, the one matching SEP.join(SEQ), and try
using | as the join op (though others, such as <>, ~, @, ::, |>, etc.
are available):

SEQ | SEP := SEQ[1] + SEP + SEQ[2] + SEP + ...

Perhaps though, we'd like a family similar to OP=, so we'd have OP|,
and we could say:

SEQ +| SEP := SEQ[1] + SEP + SEQ[2] + SEP + ...

Though this is a bit unwieldy. Perhaps it is time to support something
like the Infix class from the cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/384122

This would let us decorate a join builtin with the infix decorator,
and then say:

SEQ |join| SEP, or, depending upon the join arg order, SEP |join| SEQ

> 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.
>
> The ability to omit the joiner in most cases works particularly well
> with genexps, e.g.
>
> join(str(x) for x in whatever)
>
> ve
>
> join('', (str(x) for x in whatever))
>
>
> Alex
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/crutcher%40gmail.com
>


--
Crutcher Dunnavant <crutcher at gmail.com>
littlelanguages.com
monket.samedi-studios.com


More information about the Python-3000 mailing list