启动python shell时自动执行指定的脚本?


Pythonxy有一桩好处,就是可以在某个特定的文件夹里写若干个start script,比如我写了个:


 import numpy as np
import scipy as sp

这样待会启动Pythonxy的shell时就可以直接使用np和sp了,非常方便。

现在问题来了,我要怎么在普通python shell中实现这种功能?

我的目的是在python shell启动的时候,就有很多东西被import进来了,这样在反复开启shell测试代码的情况下非常方便。

或者有更好的方案,希望大神出来解答~~~

python shell import

黑zero银 10 years, 1 month ago

看文档呀喵…… http://docs.python.org/3/using/cmdline.html#envvar-PYTHONSTARTUP

这个明明是 Python 解释器自带的功能,设置 PYTHONSTARTUP 环境变量到你的启动脚本。

尤利·隆威尔 answered 10 years, 1 month ago

Your Answer