Is there a way to globally set the print function separator?

Chris Angelico rosuav at gmail.com
Mon Oct 9 16:47:25 EDT 2017


On Tue, Oct 10, 2017 at 7:40 AM, John Black <jblack at nopam.com> wrote:
> In article <mailman.52.1507567528.12137.python-list at python.org>,
> __peter__ at web.de says...
>>
>> John Black wrote:
>>
>> > I want sep="" to be the default without having to specify it every time I
>> > call print.  Is that possible?
>>
>> No, but you can replace the print function with your own:
>>
>> >>> print = functools.partial(print, sep="")
>> >>> print("I", "recommend", "you", "choose", "another", "name", "and",
>> "preserve", "your", "sanity")
>> Irecommendyouchooseanothernameandpreserveyoursanity
>>
>> And everybody else's.
>
>     print=functools.partial(print, sep="")
> NameError: name 'functools' is not defined

It's a module you can import.

ChrisA



More information about the Python-list mailing list