I'm writing a shell script which runs a command through ipython with the -c option like this:
我正在編寫一個shell腳本,它通過ipython運行一個命令,使用-c選項,如下所示:
ipython -c "from blah import myfunct; myfunct()"
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:
但是我想通過django的shell_plus命令調用ipython,這樣我就可以利用shell_plus自動為我加載的所有內容:
$ ./manage.py shell_plus
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?
我不能只在結尾加上“-c…”,因為管理。py不知道該怎么處理它。有沒有什么辦法來實現-c選項呢?
1 个解决方案
#1
2
There are a couple of ways to do this.
有幾種方法可以做到這一點。
Modify manage.py and add the -c option and remove it from sys.argv after processing
修改管理。並添加-c選項並從sys中刪除。argv處理后
Modify manage.py and monkeypatch shell_plus so it supports -c by default
修改管理。py和monkeypatch shell_plus默認支持-c
Put your code in some file and call 'PYTHONSTARTUP=your_file ./manage.py shell_plus'
將代碼放在某個文件中,並調用'PYTHONSTARTUP=your_file ./manage。py shell_plus”