liveBook · Manning

Clear_screen

As explained in Practices of the Python Pro

clear_screen is a book-specific function that clears the terminal display before presenting new application output.

clear_screen clears the terminal before showing a menu or executing a command, keeping the user’s current context easy to see. section 6.3.3

The function selects cls on Windows and clear elsewhere, then delegates the operation to the operating system with os.system. section 6.3.3

Terminal-aware clearing

import os def clear_screen(): clear = 'cls' if os.name == 'nt' else 'clear' os.system(clear) Call clear_screen() before printing menu options and again before running the selected option. section 6.3.3

import os


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

Shows the complete operating-system-aware implementation of clear_screen. section 6.3.3

How Practices of the Python Pro covers it

How deep it goes
Defines a short platform check and system call, but does not explore terminal internals.
Examples
Uses a Python function that chooses cls or clear and runs it before menus and selected commands.
What it assumes
Assumes basic Python functions, imports, conditional expressions, and operating-system command execution.
What you can do after
Builds a platform-aware terminal-clearing helper and places it at key points in an interactive menu.
How it connects
Links presentation layers with operating-system commands, menus, command execution, and application loops.

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.