[Python-ideas] textFromMap(seq , map=None , sep='' , ldelim='', rdelim='')
Terry Reedy
tjreedy at udel.edu
Mon Oct 25 21:27:52 CEST 2010
On 10/25/2010 9:49 AM, spir wrote:
> Hello,
>
>
> A recommended idiom to construct a text from bits -- usually when the
> bits themselves are constructed by mapping on a sequence -- is to
> store the intermediate results and then only join() them all at once.
> Since I discovered this idiom I find myself constantly use it, to the
> point of having a func doing that in my python toolkit:
>
> def textFromMap(seq , map=None , sep='' , ldelim='',rdelim=''):
'map' is a bad parameter name as it 1. reuses the builtin name and 2.
uses it for a parameter (the mapped function) of that builtin.
...
> (2) I think the same about join: should be "seq.join(sep)" since for
> me the object on which the method applies is seq, not sep.
The two parameters for the join function are a string and an iterable of
strings. There is no 'iterable of strings' class, so that leaves the
string class to attach it to as a method. (It once *was* just a function
in the string module before it and other functions were so attached.)
The fact that the function produces a string is another reason it should
be a string method. Ditto for bytes and iterable of bytes.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list