Skip to content

Commit

Permalink
Print ipython default imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevandezande committed Oct 10, 2023
1 parent 3feef38 commit f95217d
Showing 1 changed file with 16 additions and 39 deletions.
55 changes: 16 additions & 39 deletions ipython/profile_default/startup/00-useful-packages.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
#from importlib import import_module
#
## module name: Optional[what to rename it]
#packages = {
# "matplotlib": None,
# "matplotlib.pyplot": "plt",
# "numpy": "np",
# "pandas": "pd",
# "scipy": "sp",
# "sympy": "sym",
#}
#
# print("Loading:", end="")
#for name, rename in packages.items():
# if not rename:
# rename = name
# rename = import_module(package)
# print(f" {name} -> {rename},", end="")
from importlib import import_module

import matplotlib
import matplotlib.pyplot as plt
import numpy as np
packages: dict[str, str | None] = {
"matplotlib": None,
"matplotlib.pyplot": "plt",
"numpy": "np",
"pandas": "pd",
"scipy": "sp",
"sympy": "sym",
}

try:
pass
import pandas as pd
except NameError:
pass
try:
pass
import scipy as sp
except NameError:
pass

try:
import sympy as sym
sympy.init_printing()
except NameError:
pass

# Setup
for name, rename in packages.items():
mod = import_module(name)
globals()[rename or name] = mod
if rename:
print(f"{name} -> {rename}")
else:
print(f"{name}")

0 comments on commit f95217d

Please sign in to comment.