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

31st Aug 2021, 5:54 PM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
10 Réponses
+ 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)
2nd Dec 2023, 6:22 PM
Ankush Bhagat
Ankush Bhagat - avatar
+ 1
Ankush Bhagat Works great. Thanks! 👍🏽 Truly appreciated 🙏🏽
3rd Dec 2023, 8:53 PM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
0
"\033[A"  will move the cursor up one line. Use print
31st Aug 2021, 11:02 PM
Slick
Slick - avatar
0
Not working. Any chance for example code?
1st Sep 2021, 10:06 AM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
0
It works just fine. Post your code
1st Sep 2021, 10:09 AM
Slick
Slick - avatar
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)
1st Sep 2021, 10:23 AM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
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
1st Sep 2021, 10:27 AM
Slick
Slick - avatar
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.
1st Sep 2021, 10:44 AM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
0
Either way, gives me a different output on my system : hellohi Read somewhere it could have something to do with the os
1st Sep 2021, 10:54 AM
‫ירון לביא‬‎
‫ירון לביא‬‎ - avatar
0
It may be, it works on my mobile through Pydroid and Termux.
1st Sep 2021, 1:34 PM
Slick
Slick - avatar