Mailing List Archive

''.join in 1.6
Hello,

I have a question/suggestion about ''.join in Python 1.6.

Suppose I have this list:
l = ["This", "is", "a", "test"]

Currently, I would join it this way into a tab-delimeted string:
s = string.join(l, '\t')

In 1.6, I should do it this way:
'\t'.join(s)

I think it would be better to have that method on the *list*:
s.join('\t')

That's more clear, isn't it?

regards,
Gerrit.

--
Please correct any bad English you encounter in my email message!
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----
Re: ''.join in 1.6 [ In reply to ]
>>>>> "GH" == Gerrit Holl <gerrit.holl@pobox.com> writes:

GH> I think it would be better to have that method on the *list*:
GH> s.join('\t')

GH> That's more clear, isn't it?

Perhaps, but you want join to work on any sequence don't you? By
making it a method on string objects, you sort of get that for free
(as opposed to putting it on lists, sequences, and requiring all class
authors to add it as well).

-Barry
Re: ''.join in 1.6 [ In reply to ]
> In 1.6, I should do it this way:
> '\t'.join(s)
>
> I think it would be better to have that method on the *list*:
> s.join('\t')
>
> That's more clear, isn't it?

what if "s" is a tuple? an array? a user-defined
sequence type?

</F>
RE: ''.join in 1.6 [ In reply to ]
Gerrit Holl

> Currently, I would join it this way into a tab-delimeted string:
> s = string.join(l, '\t')
>
> In 1.6, I should do it this way:
> '\t'.join(s)
>
> I think it would be better to have that method on the *list*:
> s.join('\t')
>
> That's more clear, isn't it?

As Tim pointed out when they were discussed, the clearest way to express it
with the new methods is to do:

tab = '\t'

tab.join(s)

Similarly

space = ' '
space.join(s)

etc.

--david ascher
Re: ''.join in 1.6 [ In reply to ]
Fredrik Lundh wrote on 948314616:
> > In 1.6, I should do it this way:
> > '\t'.join(s)
> >
> > I think it would be better to have that method on the *list*:
> > s.join('\t')
> >
> > That's more clear, isn't it?
>
> what if "s" is a tuple? an array? a user-defined
> sequence type?

I understand. Thanks for your answers.

regards,
Gerrit.

--
Please correct any bad English you encounter in my email message!
-----BEGIN GEEK CODE BLOCK----- http://www.geekcode.com
Version: 3.12
GCS dpu s-:-- a14 C++++>$ UL++ P--- L+++ E--- W++ N o? K? w--- !O !M !V PS+ PE?
Y? PGP-- t- 5? X? R- tv- b+(++) DI D+ G++ !e !r !y
-----END GEEK CODE BLOCK-----