Comment on draft PEP for deprecating six builtins

Duncan Booth duncan at NOSPAMrcp.co.uk
Tue Apr 30 12:01:02 EDT 2002


Roman Neuhauser <neuhauser at mail.cz> wrote in 
news:mailman.1020172854.26653.python-list at python.org:

>> I prefer writing
>>    str.join(' ', aList)
>> rather than
>>    ' '.join(aList)
>> 
>> When the string is a literal I find the former reads much better. YMMV
> 
>     IMO that's because join being a string method is just awkward. How
>     does this read:
>     aList.join(' ')
>     After all, you tell the list to give you it's concatenation, using
>     the argument as the glue.

That doesn't work if you want to join a tuple, or an iterator or any other 
sequence. Dont forget you can even join a string:
>>> print str.join(',', 'abc')
a,b,c



>> Sometimes though I take advantage of it being a method:
>>    joinlines = '\n'.join
>>    ...
>>    s = joinlines(aList)
> 
>     This is not a method. You masked it as a global function.

No that is taking advantage of the fact that methods can be bound and the 
bound method then called just like any other callable object. If join 
wasn't a method it wouldn't be possible to bind it to a particular string 
in this way.

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list