如何将制表符补全添加到Python shell?

2024-05-19 02:24:57 发布

您现在位置:Python中文网/ 问答频道 /正文

当使用python manage.py shell启动django应用程序时,我得到了一个InteractiveConsole shell-我可以使用tab completion等

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)

当使用python启动python解释器时,它不提供制表符完成功能。

有人能告诉我django正在做什么来给我一个交互式控制台,或者我需要做什么来启动一个没有django应用程序的交互式控制台?


Tags: djangopybuild应用程序applemanageonshell
3条回答

我想django做了些类似https://docs.python.org/library/rlcompleter.html的事情

如果你想有一个真正好的交互式翻译看看 http://ipython.scipy.org/

我可能已经找到办法了。

创建一个文件.pythonrc

# ~/.pythonrc
# enable syntax completion
try:
    import readline
except ImportError:
    print("Module readline not available.")
else:
    import rlcompleter
    readline.parse_and_bind("tab: complete")

然后在.bashrc文件中,添加

export PYTHONSTARTUP=~/.pythonrc

这似乎管用。

作为记录,这在教程中有介绍:http://docs.python.org/tutorial/interactive.html

相关问题 更多 >

    热门问题