-1

I'm Trying To Clear a Line In a Console Like This:

Confirm? yes

Placing Order...

Then:

Confirm? yes

Order is at the location that you've provided!

i don't want it to be:

Confirm? yes

Placing Order...
Order is at the location that you've provided!

This is like when you install module with pip, the progress bar just stays in the same line and not onto another line.

I'm using Python 3.10

kielspiel
  • 61
  • 6
  • If terminal supports **ANSI** then use `sys.stdout.write("\033[2K")`, otherwise use `sys.stdout.write('\r' + (' ' * shutil.get_terminal_size()[0]))`. Now here are notes. 1. `sys.stdout.write` is like `print` but with `end` argument being not '\n'. 2. You need to import `sys` with `import sys` to use my functions and additionally you need to import `shutil` in second choice. 3. You can see ANSI sequences here **[ANSI SEQUENCES GIST](https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797)** – UltraStudioLTD Dec 30 '21 at 12:04
  • I just found out that just put an ```\r``` in the ```end``` parameter in print – kielspiel Jan 31 '22 at 23:05
  • 1
    That doesn't clear the line, just puts cursor position at the start of start line. Using this you can overwrite text written on that line but it doesn't clear it. – UltraStudioLTD Feb 01 '22 at 05:22
  • @UltraStudioLTD Yes, I know but I'll use it for now – kielspiel Feb 03 '22 at 02:24
  • the stdout.write just outputs intigers – kielspiel Feb 03 '22 at 02:40
  • If I remember correctly that is length of argument. I mean if you pass `"foo"`, it will output **3** and so on. It's like `return len(arg)` ending – UltraStudioLTD Feb 03 '22 at 13:38

1 Answers1

-2

You can use the python's os module to use the console's clear command. For example,

confirm = input("confirm? ")
if confirm.lower() in ["yes", "y"]:
    print("Placing Order...")
os.system("clear")
addressConfirm = input("confirm? ")
if addressConfirm.lower() in ["yes", "y"]:
    print("Order is at the location that you've provided!")
Asdvamp
  • 1
  • 1
  • 1
    OP is asking to clear a single line not the entire console screen. Also `clear` command works only on **Linux** and **Unix-like** terminals. – UltraStudioLTD Dec 30 '21 at 11:57