Cross-Platform Console Clearing? [duplicate]











up vote
1
down vote

favorite













This question already has an answer here:




  • How to clear the interpreter console?

    33 answers




What do I need to do if I want to clear the console without OS-Limitations?
I know that on Linux and Mac the command "clear" exists, whereas Windows has "cls".
I want to clear the console every now and then on the three major systems without personally choosing "clear" or "cls".



My idea so far was



import platform
os = platform.system()
if os == "Windows":
clear = 'cls'
else:
clear = 'clear'


and then just use clear as variable for both, depending on the OS, but it doesn't work. Is something like this actually possible?










share|improve this question













marked as duplicate by BartoszKP, Matthieu Brucher, Umair, GhostCat, Oussema Aroua 2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
    – BartoszKP
    2 days ago















up vote
1
down vote

favorite













This question already has an answer here:




  • How to clear the interpreter console?

    33 answers




What do I need to do if I want to clear the console without OS-Limitations?
I know that on Linux and Mac the command "clear" exists, whereas Windows has "cls".
I want to clear the console every now and then on the three major systems without personally choosing "clear" or "cls".



My idea so far was



import platform
os = platform.system()
if os == "Windows":
clear = 'cls'
else:
clear = 'clear'


and then just use clear as variable for both, depending on the OS, but it doesn't work. Is something like this actually possible?










share|improve this question













marked as duplicate by BartoszKP, Matthieu Brucher, Umair, GhostCat, Oussema Aroua 2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.















  • Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
    – BartoszKP
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite












This question already has an answer here:




  • How to clear the interpreter console?

    33 answers




What do I need to do if I want to clear the console without OS-Limitations?
I know that on Linux and Mac the command "clear" exists, whereas Windows has "cls".
I want to clear the console every now and then on the three major systems without personally choosing "clear" or "cls".



My idea so far was



import platform
os = platform.system()
if os == "Windows":
clear = 'cls'
else:
clear = 'clear'


and then just use clear as variable for both, depending on the OS, but it doesn't work. Is something like this actually possible?










share|improve this question














This question already has an answer here:




  • How to clear the interpreter console?

    33 answers




What do I need to do if I want to clear the console without OS-Limitations?
I know that on Linux and Mac the command "clear" exists, whereas Windows has "cls".
I want to clear the console every now and then on the three major systems without personally choosing "clear" or "cls".



My idea so far was



import platform
os = platform.system()
if os == "Windows":
clear = 'cls'
else:
clear = 'clear'


and then just use clear as variable for both, depending on the OS, but it doesn't work. Is something like this actually possible?





This question already has an answer here:




  • How to clear the interpreter console?

    33 answers








linux python-3.x windows






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









Kasai kemono

83




83




marked as duplicate by BartoszKP, Matthieu Brucher, Umair, GhostCat, Oussema Aroua 2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by BartoszKP, Matthieu Brucher, Umair, GhostCat, Oussema Aroua 2 days ago


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
    – BartoszKP
    2 days ago


















  • Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
    – BartoszKP
    2 days ago
















Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
– BartoszKP
2 days ago




Seems there is no better way, just different syntactical variations of what you've proposed - see the duplicate and other questions, which should be easy to find.
– BartoszKP
2 days ago












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










For accuracy use sys and as a good practice use subprocess



#usr/bin/env python

from sys import platform
from subprocess import run

command = {'win32': 'cls', 'linux': 'clear'}

if __name__ == '__main__':
run(command[platform], shell=True)


As BartoszKP said there are many ways of doing this, I find this a very clean way of doing it.






share|improve this answer








New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • And for instance, your code snippet does work.
    – Surister
    2 days ago










  • I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
    – Kasai kemono
    2 days ago


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










For accuracy use sys and as a good practice use subprocess



#usr/bin/env python

from sys import platform
from subprocess import run

command = {'win32': 'cls', 'linux': 'clear'}

if __name__ == '__main__':
run(command[platform], shell=True)


As BartoszKP said there are many ways of doing this, I find this a very clean way of doing it.






share|improve this answer








New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • And for instance, your code snippet does work.
    – Surister
    2 days ago










  • I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
    – Kasai kemono
    2 days ago















up vote
0
down vote



accepted










For accuracy use sys and as a good practice use subprocess



#usr/bin/env python

from sys import platform
from subprocess import run

command = {'win32': 'cls', 'linux': 'clear'}

if __name__ == '__main__':
run(command[platform], shell=True)


As BartoszKP said there are many ways of doing this, I find this a very clean way of doing it.






share|improve this answer








New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


















  • And for instance, your code snippet does work.
    – Surister
    2 days ago










  • I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
    – Kasai kemono
    2 days ago













up vote
0
down vote



accepted







up vote
0
down vote



accepted






For accuracy use sys and as a good practice use subprocess



#usr/bin/env python

from sys import platform
from subprocess import run

command = {'win32': 'cls', 'linux': 'clear'}

if __name__ == '__main__':
run(command[platform], shell=True)


As BartoszKP said there are many ways of doing this, I find this a very clean way of doing it.






share|improve this answer








New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









For accuracy use sys and as a good practice use subprocess



#usr/bin/env python

from sys import platform
from subprocess import run

command = {'win32': 'cls', 'linux': 'clear'}

if __name__ == '__main__':
run(command[platform], shell=True)


As BartoszKP said there are many ways of doing this, I find this a very clean way of doing it.







share|improve this answer








New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this answer



share|improve this answer






New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









answered 2 days ago









Surister

16




16




New contributor




Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Surister is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • And for instance, your code snippet does work.
    – Surister
    2 days ago










  • I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
    – Kasai kemono
    2 days ago


















  • And for instance, your code snippet does work.
    – Surister
    2 days ago










  • I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
    – Kasai kemono
    2 days ago
















And for instance, your code snippet does work.
– Surister
2 days ago




And for instance, your code snippet does work.
– Surister
2 days ago












I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
– Kasai kemono
2 days ago




I feel a bit ashamed now. I checked my code again and realized that I shouldn't use "os" as variable when I want to call "os.system(clear)"...
– Kasai kemono
2 days ago



Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen