[Python-checkins] CVS: python/dist/src/Lib string.py,1.46,1.47

Adrian Eyre a.eyre at optichrome.com
Mon Feb 14 13:56:39 EST 2000


> And what should ['a',3,None,[Tim(1),Tim(2)]].join(';') return?

The same as string.join(['a',3,None,[Tim(1),Tim(2)]], ';') or
";".join(['a',3,None,[Tim(1),Tim(2)]])

> It would be most bizarre to have a method on list that only 
> worked for certain kinds of lists, (and guessing your intent is 
> the specialty of that other language).

Fair point. I see the conversion from string.method(x, y) to
x.method(y), not y.method(x).

It doesn't feel like join is an instance method of a string.
Putting join onto the string implies you are 'join'ing the
string. 

If string.split() and string.join() are logically inverse
functions, one converting from string to list and one converting
from list to string, how, from an OO perspective, can they both
end up as instance methods on the same type?

Maybe " ".join should be renamed to:
" ".useThisAsTheSeparatorToJoin(["my", "list"])

Furthermore, this will make a previously optional argument
(separator) compulsory.

> Your needs are met by (", ").join("a:b:c".split(":")). Requiring 
> the arg to be a list-of-strings is restrictive, but not bizarre.

The other alternative would be to allow it on all lists, but run
the list through...

map(lambda x: str(x), <list>)

...first.

-----------------------------------------------------------------
Adrian Eyre <a.eyre at optichrome.com> - http://www.optichrome.com 





More information about the Python-list mailing list