gpt4 book ai didi

python - 在 .pythonrc.py 中检测可执行文件(python?ipython?)

转载 作者:太空宇宙 更新时间:2023-11-04 01:11:03 28 4
gpt4 key购买 nike

我意识到我有一个相当大的 ~/.pythonrc.py ,特别是有助于 pretty-print 和制表符完成。

但我现在正在使用 ipython很多和一些在 .pythonrc.py 中执行的命令让我很烦并且在发布时放慢了速度。

与其删除文件或注释掉文件,不如根据是否启动python有条件地执行脚本。或 ipython .

我该怎么做?
如何从内部检测启动脚本 .pythonrc.py

注意:sys.argv.pythonrc.py 中使用时没有帮助

最佳答案

我认为您可以使用 Detecting when a python script is being run interactively in ipython 中使用的响应,即在你的 pythonrc 文件中,检测变量 __IPYTHON__ 是否存在:

def in_ipython():
try:
__IPYTHON__
except NameError:
return False
else:
return True

关于python - 在 .pythonrc.py 中检测可执行文件(python?ipython?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27635907/

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