本文介绍了通过django的shell_plus编写ipython脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个shell脚本,通过ipython运行命令,使用-c选项,如下所示:
I'm writing a shell script which runs a command through ipython with the -c option like this:
ipython -c "from blah import myfunct; myfunct()"
但我想通过django的shell_plus命令调用ipython所以我可以利用shell_plus为我自动加载的所有东西:
but I want to invoke ipython through django's shell_plus command so I can take advantage of all the stuff shell_plus automatically loads for me:
$ ./manage.py shell_plus
我不能只添加-c ...到底,因为manage.py没有知道如何处理它。是否有办法以某种方式管道-c选项?
I can't just add "-c ..." to the end of that because manage.py doesn't know what to do with it. Is there any way to pipe the -c option somehow?
推荐答案
有几种方法可以做到这一点。
There are a couple of ways to do this.
- 修改manage.py并添加-c选项并在处理后将其从sys.argv中删除
- 修改manage.py和monkeypatch shell_plus所以它默认支持-c
- 将代码放在某个文件中并调用
'PYTHONSTARTUP = your_file ./manage.py shell_plus'
- Modify manage.py and add the -c option and remove it from sys.argv after processing
- Modify manage.py and monkeypatch shell_plus so it supports -c by default
- Put your code in some file and call
'PYTHONSTARTUP=your_file ./manage.py shell_plus'
这篇关于通过django的shell_plus编写ipython脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!