Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')
like image 562
Oskar Persson Avatar asked Jan 31 '26 02:01

Oskar Persson


1 Answers

Found here that the correct command to use was tput reset

import os

clear = lambda : os.system('tput reset')
clear()
like image 100
Oskar Persson Avatar answered Feb 01 '26 14:02

Oskar Persson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!