Skip to content

Instantly share code, notes, and snippets.

@mildsunrise
Created July 17, 2012 16:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mildsunrise/3130325 to your computer and use it in GitHub Desktop.
Save mildsunrise/3130325 to your computer and use it in GitHub Desktop.
"clear" command in Python
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()
@math2001
Copy link

Pretty cool!

@berndGEO
Copy link

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