pythonmacosscreenshot

Python clear the screen


I am still trying to make my quiz, but I want to enter a clear the screen code for my questions. So, after researching, I found a code that works, but it puts my questions way to the bottom of the screen. Here is a screenshot I took:

The Image is below

here is a example of the clear the screen code I found:

print "\n" * 40

So I tried changing the "40" To "20" but there was no effects. I am operating on Mac so the

import os
os.system('blahblah')

does not work. Please help!


Solution

  • As @pNre noted, this question shows you how to do this with ASCI escape sequences.

    If you'd like to do this using the os module, then on Mac the command is clear.

    import os
    os.system('clear')
    

    Note: The fact that you are on a Mac does not mean os.system('blahblah') will not work. It is more likely the command you are passing to os.system was erroneous.

    See answer below for how to do this on Windows/Linux.