Create a gist now

Instantly share code, notes, and snippets.

"clear" command in Python
class clear:
def __call__(self):
import os
if'ce','nt','dos'): os.system('cls')
elif'posix': os.system('clear')
else: print('\n'*120)
def __neg__(self): self()
def __repr__(self):
self();return ''
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()

Pretty cool!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment