首頁 >後端開發 >Python教學 >如何使用預先匯入的套件啟動 python 或 ipython。

如何使用預先匯入的套件啟動 python 或 ipython。

王林
王林原創
2024-08-23 06:03:38366瀏覽

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