0

After entering data and displayed something, I want to get clear the console. eg:-

num1=int(input('Number 1: '))
print(num1)

Then in the next code line, I want to clear the console to next process, without cleaning the num1 variable value.

This is the java method that can solve my problem. I want the python code as this.

public final static void clearConsole() {
         try {
             final String os = System.getProperty("os.name");
             if (os.contains("Windows")) {
                new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
             } else {
                 System.out.print("\033[H\033[2J");
                 System.out.flush();
             }
         } catch (final Exception e) {
         e.printStackTrace();
         // Handle any exceptions.
         }
    }

2 Answers2

0

do you mean something like this?

import os

num1=int(input('Number 1: '))
_ = os.system("clear")

print(num1)

cleaning the console between the entering data and the print.

NahuelBrandan
  • 633
  • 6
  • 16
0

You need the os module for this. cls is the clear console command for windows. If you are using a Linux distro it will be clear

import os

num1 = int(input('Number 1: '))
print(num1)

os.system("cls")

print(num1)

When I run this, I still can access the value of the variable num1

Pro Chess
  • 831
  • 1
  • 8
  • 23
  • Check that thread > https://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window There is no way you can clear the console of an IDLE. Run your script from terminal as `python your_script.py` – Pro Chess Nov 15 '20 at 15:14