[Python-ideas] The non-obvious nature of str.join (was Re: sum(...) limitation)
Terry Reedy
tjreedy at udel.edu
Tue Aug 12 02:15:12 CEST 2014
On 8/11/2014 6:23 PM, Wolfgang Maier wrote:
> On 12.08.2014 00:15, Terry Reedy wrote:
>> Nasty is a subclass of object, with no default value. Make it a real
>> str subclass and join works fine.
>>
>> class Nasty(str):
>> def __radd__(self, other):
>> return other + "foo"
>>
>> print("".join(["some", "strings", "and", "one", Nasty()]))
If one runs a program with a print statement from an Idle editor,
>> >>>
>> somestringsandone
the shell prints the >>> prompt and then the output. I copy the prompt
as a separator.
> No, it's not,
I have been copy and pasting python code and output for over 17 years.
You could have verified that I did so accurately here in less than a
minute. I keep the Idle icon pinned to my task bar and usually have a
scratch file for experiments in its recent files list, if not already
open, to make this sort of thing easy.
> at least not as intended
I was talking about reality, not intentions that were not clear to me.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list