首页  >  文章  >  后端开发  >  如何使用预先导入的包启动 python 或 ipython。

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

王林
王林原创
2024-08-23 06:03:38337浏览

Instead of every time you execute python or ipython, have to write "import os" or other common packages, this script will start python with these packages imported

#!/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

How to start python or ipython with packages pre-imported.

以上是如何使用预先导入的包启动 python 或 ipython。的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn