Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to clear screen in Python interactive shell mode?

Reply
Thread Tools

How to clear screen in Python interactive shell mode?

 
 
A. L.
Guest
Posts: n/a
 
      09-16-2005
In Python interactive mode, is there some function acting like 'clear'
command in bash? Could somebody here give some advice?

Thanks in advance.

 
Reply With Quote
 
 
 
 
Laszlo Zsolt Nagy
Guest
Posts: n/a
 
      09-16-2005
A. L. wrote:

>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

 
Reply With Quote
 
 
 
 
A. L.
Guest
Posts: n/a
 
      09-16-2005
Thank you very much. I have tested it under Cygwin, and that works. But
it fails under Windows Python Shell Mode.

 
Reply With Quote
 
Steven D'Aprano
Guest
Posts: n/a
 
      09-16-2005
On Thu, 15 Sep 2005 21:18:33 -0700, A. L. wrote:

> 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


--
Steven.

 
Reply With Quote
 
A. L.
Guest
Posts: n/a
 
      09-16-2005
I have tested it under windows python console, and it works.

Thank you very much.

 
Reply With Quote
 
bruce
Guest
Posts: n/a
 
      09-16-2005
elif os.name in ("nt", "dos", "ce"):
# emacs/Windows
What`s the right statement here?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
clear shell screen Shawn Minisall Python 1 10-31-2007 06:54 AM
Re: clear shell screen Shawn Minisall Python 1 10-30-2007 05:34 AM
Re: clear shell screen Gabriel Genellina Python 0 10-29-2007 06:47 AM
Start a python interactive shell from python. Bo Peng Python 2 01-26-2006 06:46 PM



Advertisments