How to clear screen in Python

preview_player
Показать описание
The tutorial is about how to clear screen in Python.
Рекомендации по теме
Комментарии
Автор

Thank you. I've been searching for this for weeks. It seems many people had one or two of the commands but NOBODY put it all together. There are MANY video clips that simply don't work because they don't include all the pieces.

rlwalker
Автор

Thank you much! I've been trying to find this for ages and all the other videos I've watched have been useless. Keep up the great work👍

nordic
Автор

Thank you so much bro really I appreciate your efforts..

praneethnair
Автор

OK people who think its not working do like this

>>>import SPACE os then ENTER
>>>def SPACE cls(): ENTER
.. "press tab button and write" os.system SPACE ("CLS") Enter
.. again press enter button
>>> cls ()

shahidbaig
Автор

Nice Music _ Reflection MK2 .. Thanks for sharing

prafulldani
Автор

This can be solved in a platform neutral manner, rather than platform dependent call in this video, using the following 2 methods:

1)
import os
def cls():
os.system('cls' if os.name=='nt' else 'clear')
cls()

2)
print("\n" * 100)

Caveat: method 2 above only works with Openstep (a BSD based OS acquired via Apple's purchase of NeXT 20 years ago) based MAC OS X and above.

hterrebrood
Автор

I followed the steps, got into C:\Windows\System32\cmd.exe DOS prompt python directory (python37-32), entered the commands, and it clears the screen in python "within" the cmd.exe dos prompt, but when I try cls() in the IDLE (shell), it doesn't work. :(


Is there a way to do this from the IDLE? Or am I stuck with Shell > Restart Shell, which clears the IDLE "buffer memory", but not the screen.


I get the impression, from looking at other videos and comments, the workaround is to do a function that creates lines with "\n", so the screen scrolls downward until the shell clears.


Side note for new people using cmd.exe: ( >>>exit() to leave the python prompt and return to the regular DOS prompt.)

algemmegla
Автор

it clears cmd but does not work on python shell

ahmedsiddique
Автор

Thanks for the video, what song is that?

markaskfjh
Автор

+Saroj Mahato Hello Saroj :) I like your code, its understandable but mine doesnt work ... :( dont know why... I didnt import any library, i just installed pycharm and python interpreter 3.5
it all works fine, print() for() but it doesnt clear the screen. it runs fine, no errors, green light up top right with no indications of error lines and instead of clearing the screen, it puts a block, like the ones when it doesnt understand the language(greek, and other languages other than latin characters)

exactly the same as with this code:
import os
os.system('cls' if os.name == 'nt' else 'clear')

why's that? pls help if you can :) good job for your help :) i appreciate this even when not solved :) or someone else help? thnx ;)

EDIT: In interpreter, as yours, btw i use 3.5(64 bit), works fine as yours ;) but in pycharm it doesnt ... why?

John_X_GR
Автор

Actually my screen is not clear using this code what can i do

aishwaryanamdev
Автор

import os
def cls():
os.system ("CLS")

cls()

adrianhalle
welcome to shbcf.ru