How to clear screen in Python interactive shell mode?

A

A. L.

In Python interactive mode, is there some function acting like 'clear'
command in bash? Could somebody here give some advice?

Thanks in advance.
 
L

Laszlo Zsolt Nagy

A. L. said:
In Python interactive mode, is there some function acting like 'clear'
command in bash? Could somebody here give some advice?
Under Linux/UNIX system (on x86 at least) you can use the CTRL+L
combination to clear the screen.
I do not now similar for Windows and MACs.

Les
 
A

A. L.

Thank you very much. I have tested it under Cygwin, and that works. But
it fails under Windows Python Shell Mode.
 
S

Steven D'Aprano

In Python interactive mode, is there some function acting like 'clear'
command in bash? Could somebody here give some advice?

Thanks in advance.


Something like this may help:

def clearscreen(numlines=100):
"""Clear the console.

numlines is an optional argument used only as a fall-back.
"""
import os
if os.name == "posix":
# Unix/Linux/MacOS/BSD/etc
os.system('clear')
elif os.name in ("nt", "dos", "ce"):
# DOS/Windows
os.system('CLS')
else:
# Fallback for other operating systems.
print '\n' * numlines
 
B

bruce

elif os.name in ("nt", "dos", "ce"):
# emacs/Windows
What`s the right statement here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top