0
Python - how can I enable to output stream to go 1 line up (using the sys.stdout.write)?
Backspace ("\b") would go only till beginning of line. sys.stdout.write("\033[A","\033[F") not working neither. Pycharm editor doesn't seem to recognize the part of "[A" and "[F" as part of the escape character of "\033" so I suspect this could hint on part of the problem
10 odpowiedzi
+ 3
# Here's the working code:
from time import sleep
line_up = "\033[A"
for i in range(101):
print(f"line 1: {i}")
if i == 100:
break
print(f"line 2: {i}", end=line_up)
print("", end="\r")
sleep(0.1)
+ 1
Ankush Bhagat Works great. Thanks! 👍🏽 Truly appreciated 🙏🏽
0
"\033[A" will move the cursor up one line. Use print
0
Not working. Any chance for example code?
0
It works just fine. Post your code
0
import time
import sys
For i in range(20):
time.sleep(0.1)
print("\033[A" * 3)
print(f"{i} : bbb{i}eee")
print("\033[A" * 3)
0
You can't just go up 3 lines if you only go down 2. What are you trying to do exactly?
print()
print("hello", end="\033[A")
print("hi")
# output
hi
hello
0
I know. But I assumed it has a similar behavior to backspace, so if it gets the cursor to the top most part if the console, it takes no further effect, even if keep using it, and the cursor just stays at the top most part.
0
Either way, gives me a different output on my system :
hellohi
Read somewhere it could have something to do with the os
0
It may be, it works on my mobile through Pydroid and Termux.