multiple prints on the same line in Python

前端 未结 17 2547
独厮守ぢ
独厮守ぢ 2020-11-22 06:06

I want to run a script, which basically shows an output like this:

Installing XXX...               [DONE]

Currently, I print Installi

17条回答
  •  忘掉有多难
    2020-11-22 06:28

    Found this Quora post, with this example which worked for me (python 3), which was closer to what I needed it for (i.e. erasing the whole previous line).

    The example they provide:

    def clock():
       while True:
           print(datetime.now().strftime("%H:%M:%S"), end="\r")
    

    For printing the on the same line, as others have suggested, just use end=""

提交回复
热议问题