-6

What would the fastest way to clear the screen, be?

I've tried many solutions, they seem to work, however, I need the fastest way. Could anyone point me in the right direction?

The screen, in my case, is a command prompt.

I've edited my question for better understandings.

Any help welcomed :)

braX
  • 11,506
  • 5
  • 20
  • 33
Coolq B
  • 344
  • 5
  • 10
  • 1
    Have you run any timeits or other measures to see which is fastest? There are a [number of answers](http://stackoverflow.com/questions/18937058/python-clear-screen-in-shell) for this question and it should not be hard for you to test them (and would avoid any variance between systems affecting the runtimes) – LinkBerest Aug 25 '16 at 23:35
  • Thank you! I don't know how I didn't see that page :) – Coolq B Aug 25 '16 at 23:38
  • How fast does it need to be? – Peter Wood Aug 25 '16 at 23:46
  • 2
    It sounds like you might be interested in a library like [UniCurses](https://pypi.python.org/pypi/UniCurses) that lets you manipulate the terminal more directly. – user2357112 Aug 25 '16 at 23:55
  • Thanks, I'll look into it ;) – Coolq B Aug 25 '16 at 23:59

1 Answers1

4

One portable solution could be:

def clear_sceen():
    os.system('cls' if os.name == 'nt' else 'clear')

Another possible way would be using:

print(chr(27) + "[2J")

Although this one wouldn't be really a portable solution

BPL
  • 9,632
  • 9
  • 59
  • 117
  • Hi, thank you for your reply. :) however, I said in my post, That I've used os.system('cls') and it was a bit slow :) I appreciate your answer though ;D – Coolq B Aug 25 '16 at 23:39
  • 1
    @CoolqB Edited my answer – BPL Aug 25 '16 at 23:45