Is there a way to globally set the print function separator?
eryk sun
eryksun at gmail.com
Mon Oct 9 17:47:11 EDT 2017
On Mon, Oct 9, 2017 at 10:04 PM, John Black <jblack at nopam.com> wrote:
> In article <org8pq$fgm$1 at gioia.aioe.org>, python at example.invalid says...
>>
>> Le 09/10/2017 à 18:22, John Black a écrit :
>> > I want sep="" to be the default without having to specify it every time I
>> > call print. Is that possible?
>>
>> >>> oldprint = print
>> >>> def print(*args,**kwargs):
>> ... oldprint(*args,**kwargs,sep='')
>> ...
>> >>> print(1,2,3)
>> 123
>
> Winner! Thanks all.
functools.partial(print, sep='') is the winner, IMO. Or even code that
use kwargs.setdefault('sep', ''). The above code is wrong in a way
that leads to a TypeError. Can you see the problem?
More information about the Python-list
mailing list