gpt4 book ai didi

python - 是否可以启动带有一些预导入模块的 Paster shell?

转载 作者:太空狗 更新时间:2023-10-30 01:30:40 27 4
gpt4 key购买 nike

是否可以运行“paster shell blah.ini”(或其变体)并让它自动加载某些库?

我讨厌必须总是在每个 paster shell 中输入“from foo.bar import mystuff”作为第一个命令,并且希望计算机为我做这件事。

最佳答案

尝试的一个选项是创建一个 sitecustomize.py 脚本。如果你把它和你的 paster shell 放在同一个文件夹中,python 解释器应该在启动时加载它。

让我澄清一下,如果找到 sitecustomize.py,它总是在解释器启动时加载。因此,如果您将它放在可以找到它的地方,最好是只有在 paster shell 启动时才能找到的地方,那么您应该能够将您的导入添加到它并让它们准备就绪。

这可能是您最好的选择。如果 paster shell 是一个打包的应用程序(一个 py2exe),它应该仍然可以工作。

另见:

http://www.rexx.com/~dkuhlman/pylons_quick_site.html#using-an-ipython-embedded-shell http://pylonshq.com/project/pylonshq/ticket/428

关于python - 是否可以启动带有一些预导入模块的 Paster shell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/922351/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com