我意识到我有一个相当大的~/.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/