我想别人可能会问这个,但我找不到。我的问题是,我的.ipython/ipy_user_conf.py中有以下陈述:ip.ex('import matplotlib as mat')
ip.ex('import matplotlib.pyplot as plt')
ip.ex('import numpy as np')
ip.ex('import pupynere as pu')
ip.ex('import g')
ip.ex('import bsite')
ip.ex('import csvf')
ip.ex('import pandas as pa')
ip.ex('import pickle as pk')
ip.ex('import mathex as mathex')
ip.ex('import os as os')
ip.ex('import re as re')
ip.ex('import scipy as sp')
ip.ex('import mpl_toolkits.basemap as bmp')
ip.ex('from mpl_toolkits.basemap import cm')
如果我在ipythonshell中使用python,那么在我启动ipython时将直接加载这些模块,但是如果我有一个python脚本,例如,ba_plot.py用于绘制一些绘图。我在ipython中通过交互方式调试了脚本,但是我想在shell终端中运行它,比如:
^{pr2}$
但在此之前,每次我需要在ba_plot.py文件的开头复制以下内容:import matplotlib as mat
import matplotlib.pyplot as plt
import numpy as np
import pupynere as pu
import g
import bsite
import csvf
import pandas as pa
import pickle as pk
import mathex as mathex
import os as os
import re as re
import scipy as sp
import mpl_toolkits.basemap as bmp
from mpl_toolkits.basemap import cm
因为否则它会抱怨找不到模块。那么,有没有什么方法可以避免这样做呢?在python脚本的开头包含一些头文件,同时在头文件中导入所有这些模块?通过这种方式,我只需要在python脚本的开头添加online。在