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

Alex Martelli aleaxit at gmail.com
Thu Apr 27 19:18:23 CEST 2006


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.
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


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /