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:
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
}