Python 2.7: secure printing

I saw a similar entry here , however this applies to Python 2.6, and I was hoping there was an easier way.

From reading the stream, it seems the best way is to simply replace all my print statements with sys.stdout.write (s + '\ n')?

I was hoping there was a better way that allowed me to use print

+6
source share
2 answers
from __future__ import print_function print = lambda x: sys.stdout.write("%s\n" % x) 

Good cheap and dirty hack.

+12
source

I found that the following works in both a multi-threaded and multi-process environment, very simple:

 def sprint(content): print("{0}~{1}\r".format(str(datetime.datetime.now()), content)) 
0
source

Source: https://habr.com/ru/post/899970/


All Articles