ash*_*her 112 python shell interpreter
当使用启动django应用程序时python manage.py shell,我得到一个InteractiveConsole shell - 我可以使用Tab完成等.
Python 2.5.1 (r251:54863, Apr 15 2008, 22:57:26)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
Run Code Online (Sandbox Code Playgroud)
刚刚启动python解释器时python,它不提供制表符完成.
有人能告诉我django正在做什么来给我一个交互式控制台,或者我需要做什么来启动没有django应用程序的交互式控制台?
ash*_*her 196
我可能已经找到了办法.
创建一个.pythonrc文件
# ~/.pythonrc
# enable syntax completion
try:
import readline
except ImportError:
print("Module readline not available.")
else:
import rlcompleter
readline.parse_and_bind("tab: complete")
Run Code Online (Sandbox Code Playgroud)
然后在你的.bashrc文件中添加
export PYTHONSTARTUP=~/.pythonrc
Run Code Online (Sandbox Code Playgroud)
这似乎有效.
Pet*_*ann 34
我认为django做的事情就像https://docs.python.org/library/rlcompleter.html
如果你想拥有一个非常好的交互式翻译,请查看 http://ipython.scipy.org/.
小智 9
我用ptpython. https://github.com/jonathanslenders/ptpython/
ptpython是一个很棒的工具autocomplete shell cmd.安装ptpython非常简单,使用pip工具
pip install ptpython
对于django shell,你应该导入django env,就像这样
进口口
os.environ.setdefault("DJANGO_SETTINGS_MODULE","testweb.settings")
相信我,这是最好的方式!