943,724 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 1443
  • Python RSS
You are currently viewing page 1 of this multi-page discussion thread
Sep 6th, 2009
0

Clearing the screen of text

Expand Post »
I can't find a simple command that does this. If there's no command that does this I'm going to spam python.org until they finally agree to put this in the next version of python.
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Sep 6th, 2009
-1

Re: Clearing the screen of text

Python.org supposedly loves spam anyway, so long as you include some eggs.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Sep 6th, 2009
0

Re: Clearing the screen of text

I was hoping for a more insightful answer
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Sep 6th, 2009
0

Re: Clearing the screen of text

Sigh.

No, python doesn't have clear screen.
Featured Poster
Reputation Points: 975
Solved Threads: 140
Posting Virtuoso
scru is offline Offline
1,624 posts
since Feb 2007
Sep 6th, 2009
0

Re: Clearing the screen of text

there's not even some way to trick the computer into clearing the screen of text?
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Sep 6th, 2009
0

Re: Clearing the screen of text

I suggest
python Syntax (Toggle Plain Text)
  1. >>> print("\n" * 40)
Or even better
python Syntax (Toggle Plain Text)
  1. >>> def clear():
  2. ... print("\n"*40)
  3. >>> clear()
Last one:
python Syntax (Toggle Plain Text)
  1. >>> def clear():
  2. ... import sys
  3. ... for i in range(40):
  4. ... print(sys.ps1)
Last edited by Gribouillis; Sep 6th, 2009 at 4:29 pm.
Reputation Points: 930
Solved Threads: 668
Posting Maven
Gribouillis is offline Offline
2,655 posts
since Jul 2008
Sep 6th, 2009
0

Re: Clearing the screen of text

The last one doesn't work, says the attribute ps1 doesn't exist. But that is what I was planning to do at first, but then that leaves a big side bar. Oh well, I guess I'll just have to use the print thing.
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Sep 6th, 2009
3

Re: Clearing the screen of text

Clearing the display screen in console mode depends on the Operating System, that and the limited usefulness is why many multiplatform computer languages do not include it.

Here is a Python version using module os ...
python Syntax (Toggle Plain Text)
  1. import os
  2. # works on windows nt (also xp and vista) or linux
  3. os.system(['clear','cls'][os.name == 'nt'])
Last edited by vegaseat; Sep 6th, 2009 at 6:14 pm.
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Sep 6th, 2009
0

Re: Clearing the screen of text

That works perfect! Now the problem is really solved.
Reputation Points: 14
Solved Threads: 17
Junior Poster
AutoPython is offline Offline
138 posts
since Sep 2009
Oct 20th, 2009
0
Re: Clearing the screen of text
python Syntax (Toggle Plain Text)
  1. import os
  2. # works on windows nt (also xp and vista) or linux
  3. os.system(['<strong class="highlight">clear</strong>','cls'][os.name == 'nt'])
Can anyone kindly explain the background of how this bit of code works?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Warkthogus is offline Offline
16 posts
since Sep 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Problems writing code for my project
Next Thread in Python Forum Timeline: Letter frequency function using lists





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC