每次执行 python 或 ipython 时,都必须编写“import os”或其他常用包,这个脚本将启动 python 并导入这些包
#!/usr/bin/env bash # ------------------------------------------------------------- # Calls ipython or python3 with multiple packages imported # ------------------------------------------------------------- if [[ -z "$1" ]] || [[ -f "$1" ]]; then [[ -n "$(command -v ipython3)" ]] && EXEC="ipython3" || EXEC=python3 TMP_PY=/$TMPDIR/$EXEC.py printf "import os, re, sys, math, datetime, yaml\n" >$TMP_PY $EXEC -i $TMP_PY "$@" else python3 "$@" fi
以上就是如何使用预先导入的包启动 python 或 ipython的详细内容,更多请关注本网内其它相关文章!