首页 > 文章列表 > 如何使用预先导入的包启动 python 或 ipython

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

139 2024-09-10

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

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

来源:https://dev.to/a-bentofreire/how-to-start-python-or-ipython-with-packages-pre-imported-17h4

本类最新

查看更多