How to colorize the output of Python errors in the Gnome terminal?

前端 未结 4 1406
难免孤独
难免孤独 2021-02-09 19:17

Note: I am asking this question after researching how to actually do it. Other questions which are somewhat similar, but actually differ from my question relate to:

    <
4条回答
  •  情深已故
    2021-02-09 19:32

    Quick hack solution, UNIX only. Redirect stdout to a file with .py suffix. Then display file using vimcat for colorised output. Wrap this all up in a shell function. For example in bash;

    # print colorised python output
    colorized() {
        local out='out.py'
        if (( $# < 1)) 
        then
            printf "Usage: %s pyhon-script\n" $0 >&2
            return 1;
        fi
        if [ -e $out ]; 
        then
            rm $out
        fi
        python $@ 2> $out
        empty=$(stat $out | grep empty)
        if (( $? == 1 ))
        then
            vimcat $out
        fi
    }
    

提交回复
热议问题