是否有某种方法或资源我可以参考,这将允许我将我的整个应用程序导入python解释器?
例如,当我运行python一些flask-sql查询时,我必须这样做每次我退出:
python
import project
from project import app,db, etc etc
from project.models import Model, Model,
goes on and on......
Run Code Online (Sandbox Code Playgroud)
我怎样才能避免这样做以绕过重复性呢?来自Rails,它非常适合运行rails c并为您装载所有东西.
您可以通过设置环境变量让Python在交互式启动时执行文件PYTHONSTARTUP:
$ cat file.py
print 'These definitions are executed before the REPL'
pi = 3.14
$ PYTHONSTARTUP=file.py python
Python 2.7.3 (default, Mar 21 2013, 07:25:39)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
These definitions are executed before the REPL
>>> pi
3.14
>>>
Run Code Online (Sandbox Code Playgroud)
它就在底部python --help.