PHP前端开发

如何使用预先导入的包启动 python 或 ipython

百变鹏仔 3天前 #Python
文章标签 如何使用

每次执行 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" >$TMP_PY    $EXEC -i $TMP_PY "$@"else    python3 "$@"fi