Created
July 17, 2012 16:06
-
-
Save mildsunrise/3130325 to your computer and use it in GitHub Desktop.
"clear" command in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class clear: | |
def __call__(self): | |
import os | |
if os.name==('ce','nt','dos'): os.system('cls') | |
elif os.name=='posix': os.system('clear') | |
else: print('\n'*120) | |
def __neg__(self): self() | |
def __repr__(self): | |
self();return '' | |
clear=clear() | |
''' | |
Import this file (from clear import clear) | |
or paste the above lines of code into | |
your shell or in your script. | |
Then, use "-clear" to clear the screen, i.e: | |
>>> -clear | |
Or call it as a function: | |
>>> clear() | |
Or if you're on a shell, you can also type: | |
>>> clear | |
This file can be called as a regular program, also. | |
''' | |
if __name__=='__main__': clear() |
I like it! Line 6 is pretty funny :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pretty cool!