3 Replies - 53023 Views - Last Post: 01 November 2010 - 08:12 PM Rate Topic: -----

#1 Guest_yurimano*


Reputation:

Clear screen command

Posted 30 October 2010 - 03:50 AM

Is there a clear screen command in Python that clears the output screen? e.g. in Pascal, it is
 clearscr() 


thx
Is This A Good Question/Topic? 0

Replies To: Clear screen command

#2 Nallo   User is offline

  • D.I.C Regular
  • member icon

Reputation: 166
  • View blog
  • Posts: 258
  • Joined: 19-July 09

Re: Clear screen command

Posted 30 October 2010 - 05:11 AM

To the best of my knowledge there isn't.

You could make a call your os shell to clear a console window. But that is kind of ugly as it depends on which operating system you use:

For Unix/Linux:
import os
os.system('clear')


For Windows (I am not sure though, it's been ages since I last used windows):
import os
os.system('cls')

Was This Post Helpful? 0
  • +
  • -

#3 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Clear screen command

Posted 30 October 2010 - 07:00 AM

In Turbo Pascal. Borland has left us with a whole lot of DOS centric console junk.

Calling the os for something like clearing and pausing works, but isn't really favored.

Perhaps most generically:
print("\n" * 30) # or however many lines you like


Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2975
  • View blog
  • Posts: 11,224
  • Joined: 15-July 08

Re: Clear screen command

Posted 01 November 2010 - 08:12 PM

Since os.name returns 'posix', 'nt', 'dos', 'os2', 'mac', or 'ce', you can call specific options. Say I want to support nt, dos, and posix clears, then I could this:

import os
osname = os.name
if name == 'posix':
    os.system('clear')
elif name == 'nt' or name == 'dos':
    os.system('cls')
else:
    print("\n" * 30)



Thus, it clears if it can, and if it can't, it prints blank lines instead.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1