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 Nov 19 at 14:35


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
    Nov 19 at 10:53















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 Nov 19 at 14:35


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
    Nov 19 at 10:53













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 Nov 19 at 10:47









Kasai kemono

83




83




marked as duplicate by BartoszKP, Matthieu Brucher, Umair, GhostCat, Oussema Aroua Nov 19 at 14:35


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 Nov 19 at 14:35


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
    Nov 19 at 10:53


















  • 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
    Nov 19 at 10:53
















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
Nov 19 at 10:53




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
Nov 19 at 10:53












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





















  • And for instance, your code snippet does work.
    – Surister
    Nov 19 at 11:08










  • 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
    Nov 19 at 11:51


















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





















  • And for instance, your code snippet does work.
    – Surister
    Nov 19 at 11:08










  • 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
    Nov 19 at 11:51















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





















  • And for instance, your code snippet does work.
    – Surister
    Nov 19 at 11:08










  • 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
    Nov 19 at 11:51













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












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












share|improve this answer



share|improve this answer










answered Nov 19 at 11:07









Surister

161




161












  • And for instance, your code snippet does work.
    – Surister
    Nov 19 at 11:08










  • 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
    Nov 19 at 11:51


















  • And for instance, your code snippet does work.
    – Surister
    Nov 19 at 11:08










  • 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
    Nov 19 at 11:51
















And for instance, your code snippet does work.
– Surister
Nov 19 at 11:08




And for instance, your code snippet does work.
– Surister
Nov 19 at 11:08












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
Nov 19 at 11:51




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
Nov 19 at 11:51



Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]