I want to add a clear screen function to the standard function list (without importing it) such as print on python. When I invoke clear in python it should clear the screen. How can I do it?
import os
def clear():
os.system("clear")
#os.system('echo -ne "\eD\eD\eD\e[A\e[A\e[A"')
Secondly any idea why this is not working os.system('echo -ne "\eD\eD\eD\e[A\e[A\e[A"')
Edit:
Solution for os.system('echo -ne "\eD\eD\eD\e[A\e[A\e[A"') is print('\x1b[J\x1b[A\x1b[A\x1b[A'*20, end='')(py3) whole credit to this code goes to @metatoaster
os.systemto clear a screen is not cross-platform. See: stackoverflow.com/a/23980136/2904896clearcomes from and where it is documented?printand replace all\ewithchr(27)much like how I indicated using the example. Alternatively use\x1binstead, so you would replace that whole "not working" statement withprint('\x1b[2J\x1bD\x1bD\x1bD\x1b[A\x1b[A\x1b[A', end='')to both clear screen and shift the lines as you indicated.