How to clear the interpreter console?

后端 未结 30 2203
自闭症患者
自闭症患者 2020-11-21 18:15

Like most Python developers, I typically keep a console window open with the Python interpreter running to test commands, dir() stuff, help() stuff

30条回答
  •  广开言路
    2020-11-21 18:45

    EDIT: I've just read "windows", this is for linux users, sorry.


    In bash:

    #!/bin/bash
    
    while [ "0" == "0" ]; do
        clear
        $@
        while [ "$input" == "" ]; do
            read -p "Do you want to quit? (y/n): " -n 1 -e input
            if [ "$input" == "y" ]; then
                exit 1
            elif [ "$input" == "n" ]; then
                echo "Ok, keep working ;)"
            fi
        done
        input=""
    done
    

    Save it as "whatyouwant.sh", chmod +x it then run:

    ./whatyouwant.sh python
    

    or something other than python (idle, whatever). This will ask you if you actually want to exit, if not it rerun python (or the command you gave as parameter).

    This will clear all, the screen and all the variables/object/anything you created/imported in python.

    In python just type exit() when you want to exit.

提交回复
热议问题