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

王林
Release: 2024-08-23 06:03:38
Original
290 people have browsed it

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

1

2

3

4

5

6

7

8

9

10

11

12

13

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

Copy after login

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

The above is the detailed content of How to start python or ipython with packages pre-imported.. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!