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?
linux python-3.x windows
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.
add a comment |
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?
linux python-3.x windows
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
add a comment |
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?
linux python-3.x windows
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
linux python-3.x windows
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
add a comment |
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
add a comment |
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.
New contributor
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
add a comment |
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.
New contributor
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
add a comment |
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.
New contributor
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
add a comment |
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.
New contributor
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.
New contributor
New contributor
answered 2 days ago
Surister
16
16
New contributor
New contributor
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
add a comment |
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
add a comment |
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