def clear_screen(self):
"""Try to clear the terminal screen (if stdout is a terminal)."""
if self.clear_method is None:
try:
isatty = os.isatty(sys.stdout.fileno())
except Exception:
isatty = False
if isatty:
self.clear_method = "clear"
else:
self.clear_method = "delimiter"
if self.clear_method == "clear":
try:
retcode = subprocess.call("clear")
except Exception:
retcode = 1
if retcode != 0:
self.clear_method = "newlines"
if self.clear_method == "newlines":
print "\n" * (self.screen_height()+1)
elif self.clear_method == "delimiter":
print 78 * "-"
评论列表
文章目录