Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Saturday, December 12, 2015

Completely clearing the terminal window using Python

Completely clearing the terminal window using Python


How can I in Python (v 2.7.2) completely clear the terminal window?

This doesn't work since it just adds a bunch of new lines and the user can still scroll up and see earlier commands

import os  os.system('clear')  

Answer by Mattias for Completely clearing the terminal window using Python


You can not control the users terminal. That's just how it works.

Think of it like write only.

Answer by Games Brainiac for Completely clearing the terminal window using Python


I've tried this and it works:

>>> import os  >>> clear = lambda : os.system('clear')  >>> clear()  

BEFORE

Before

AFTER clear()

After

Answer by Adrien for Completely clearing the terminal window using Python


On Windows:

import os  os.system('cls')  

On Linux:

import os  os.system('clear')  

Answer by Oskar for Completely clearing the terminal window using Python


Found here that the correct command to use was tput reset

import os    clear = lambda : os.system('tput reset')  clear()  

Answer by Austin Kootz for Completely clearing the terminal window using Python


for windows:

import os  def clear(): os.system('cls')  

for linux:

import os  def clear(): os.system('clear')  

then to clear the terminal simply call:

clear()  

Answer by user5673930 for Completely clearing the terminal window using Python


No need of importing any libraries. Simply call the cls function.

cls()  

Answer by kilojoules for Completely clearing the terminal window using Python


press the control and l keys together


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.