Archive

Posts Tagged ‘windows’

[Windows] clear screen in the Python shell

February 22, 2022 Leave a comment

Problem

Under Linux, when using the Python shell, it’s very easy to clear the screen. Just press Ctrl+L. But what about Windows? Ctrl+L doesn’t work there :( Is there a painless way to clear the screen under Windows?

Solution

We’ll create a function called cls() that will clear the screen. Usage example:

C:\> python
>>> a = 5
>>> cls()

For this, create a file called .pystartup (the name doesn’t matter). Add the following function to it:

def cls():
    """
    clear screen for Windows
    """
    import os
    cmd = 'cls' if os.name == 'nt' else 'clear'
    os.system(cmd)

Create a new environment variable called PYTHONSTARTUP and assign the path of .pystartup to it. Example:

PYTHONSTARTUP=C:\opt\.pystartup

Open a new terminal. Now, if you start the Python shell, it’ll read the content of the file above. Thus, the function cls() will be available in all your Python shell sessions.

It also works under Linux. You can add more utility functions to .pystartup (however, I think it’s a good idea to keep it minimal).

Categories: python Tags: , , , , ,

PyScripter: a very nice small IDE for Windows

April 8, 2014 Leave a comment

I found a very nice small Python IDE for Windows called PyScripter.

PyScripter is a free and open-source Python Integrated Development Environment (IDE) created with the ambition to become competitive in functionality with commercial Windows-based IDEs available for other languages. Being built in a compiled language is rather snappier than some of the other Python IDEs and provides an extensive blend of features that make it a productive Python development environment.” (source)

The install file is less than 5 MB and PyScripter provides all the features you want from a modern IDE: syntax highlight, run code and see the output, code completion, built-in Python shell, debugger, etc.

Here is a youtube video for beginners that shows first how to install Python on Windows, then presents PyScripter.

Categories: python, windows Tags: , ,