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

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
# ————————————————————-
#…


This content originally appeared on DEV Community and was authored by Alexandre Bento Freire

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

Image description


This content originally appeared on DEV Community and was authored by Alexandre Bento Freire


Print Share Comment Cite Upload Translate Updates
APA

Alexandre Bento Freire | Sciencx (2024-08-21T20:36:48+00:00) How to start python or ipython with packages pre-imported.. Retrieved from https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/

MLA
" » How to start python or ipython with packages pre-imported.." Alexandre Bento Freire | Sciencx - Wednesday August 21, 2024, https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/
HARVARD
Alexandre Bento Freire | Sciencx Wednesday August 21, 2024 » How to start python or ipython with packages pre-imported.., viewed ,<https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/>
VANCOUVER
Alexandre Bento Freire | Sciencx - » How to start python or ipython with packages pre-imported.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/
CHICAGO
" » How to start python or ipython with packages pre-imported.." Alexandre Bento Freire | Sciencx - Accessed . https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/
IEEE
" » How to start python or ipython with packages pre-imported.." Alexandre Bento Freire | Sciencx [Online]. Available: https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/. [Accessed: ]
rf:citation
» How to start python or ipython with packages pre-imported. | Alexandre Bento Freire | Sciencx | https://www.scien.cx/2024/08/21/how-to-start-python-or-ipython-with-packages-pre-imported/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.