Is there some sort of method or resource I can reference that would allow me to import my entire application into the python interpreter?
For example when I run python
to do some flask-sql queries I have to do this EVERYTIME I exit:
python
import project
from project import app,db, etc etc
from project.models import Model, Model,
goes on and on......
How can I avoid doing that to bypass the repetiveness? Coming from Rails, its so nice to just run rails c
and have everything loaded for you.
You can have Python execute a file on interactive startup by setting the environmental variable 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
>>>
It's right there at the bottom of python --help
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With