我怎样才能让普洛恩读我的Python?

2024-05-09 20:36:10 发布

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

我正在使用collective.python构建。在

我有以下.pythonrc(配置为export PYTHONSTARTUP=~/.pythonrc):

import readline
import rlcompleter
readline.parse_and_bind('tab: complete')

当我在shell中运行Python时,制表符完成工作。当我在调试模式下运行Plone时,它不会。除非,我将.pythonrc的内容粘贴到Plone debug Python提示符中。我错过了什么?在

注意:只有当我通过python bootstrap.py安装Plone时,才能粘贴my.pythonrc的内容(即使用collective.pythonPython启动Plone buildout)。如果我在virtualenv中安装Plone,则没有任何效果。但至少在这种情况下,缺失的功能对我来说是有意义的(也就是说,virtualenv中可能缺少一些东西,这是使制表符完成工作所必需的。)


Tags: andimport内容readlinevirtualenvparsebind粘贴
2条回答

我知道import user。这是~/.pythonrc.py。注意.py扩展名。我已将该文件设置为我的PYTHONSTARTUP

我要把那文件贴好。几年前我就把它拼凑起来了。不确定它是否仍然是最好的,因为我看到了关于2006和python2.3的评论。不过,它确实起了作用。在

$ cat ~/.pythonrc.py 
# See http://blog.partecs.com/2006/02/27/source-inspector/
#import pydoc
import inspect
import rlcompleter, readline

readline.parse_and_bind('tab: complete')

# def source(obj):
#     """source of the obj."""
#     try:
#         pydoc.pipepager(inspect.getsource(obj), 'less')
#     except IOError:
#         pass

# From /usr/local/lib/python2.3/user.py
import os
home = os.curdir                        # Default
if 'HOME' in os.environ:
    home = os.environ['HOME']
elif os.name == 'posix':
    home = os.path.expanduser("~/")
# Make sure home always ends with a directory separator:
home = os.path.realpath(home) + os.sep

# From http://wiki.python.org/moin/PdbRcIdea
# Command line history:
histfile = home + '.pyhist'
try:
    readline.read_history_file(histfile)
except IOError:
    pass
import atexit
atexit.register(readline.write_history_file, histfile)
readline.set_history_length(200)

# Cleanup namespace
# del atexit
# del home
# del histfile
# del os
# del readline
# del rlcompleter

实例控制器使用两个命令行开关;-i用于交互模式,-c用于加载Zope配置并设置app变量。-c开关用于禁用PYTHONSTARTUP环境变量。在

您可以修改plone.recipe.zope2instance包来运行脚本。在

plone.recipe.zope2instance中,找到plone/recipe/zope2instance/ctl.py文件,将do_debug()方法更改为:

def do_debug(self, arg):
    interactive_startup = ("import os;"
        "os.path.exists(os.environ.get('PYTHONSTARTUP', '')) "
        "and execfile(os.environ['PYTHONSTARTUP']); del os;"
        'import Zope2; app=Zope2.app()')
    cmdline = self.get_startup_cmd(self.options.python,
                                   interactive_startup,
                                   pyflags = '-i', )

事实上,我非常喜欢支持PYTHONSTARTUP的想法,所以我已经对配方进行了更改,请参见rev 536f8fc1c4!在

相关问题 更多 >