Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Just a quick question:

How do you clear the screen in the shell? I've seen ways like:

import os os.system('cls')

This just opens the windows cmd, clears the screen and closes but I want the shell window to be cleared

(PS: I don't know this helps, but I'm using version 3.3.2 of Python)

Thank you :)

1 Answer

0 votes
by (106k points)
edited by

For clearing screen in the shell for OS X, you can use the subprocess module and call 'cls' from the shell:-

import subprocess as sp sp.call('cls',shell=True)

For the window you can use the following:-

tmp = sp.call('cls',shell=True)

For Linux, you must replace cls command with clear

tmp = sp.call('clear',shell=True)

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
2 answers
asked Sep 25, 2019 in Python by Sammy (47.6k points)
0 votes
4 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...