7

I've seen a similar post here however it refers to Python 2.6 and I was hoping there was an easier way.

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

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

Community
  • 1
  • 1
Setheron
  • 3,520
  • 3
  • 34
  • 52

2 Answers2

13
from __future__ import print_function
print = lambda x: sys.stdout.write("%s\n" % x)

Is a nice cheap and dirty hack.

Jakob Bowyer
  • 33,878
  • 8
  • 76
  • 91
0

I found that the following works on both multi-thread&multi-process environment, very simple:

def sprint(content):
    print("{0}~{1}\r".format(str(datetime.datetime.now()), content))
Scott 混合理论
  • 2,263
  • 8
  • 34
  • 59