作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在通过 Anaconda、Mac Sierra、iTerm 和 $SHELL=bash
运行 iPython (Jupyter) - 如果我错过了任何有用的设置细节,请告诉我.
我喜欢 bash
的 $HISTCONTROL
方面,提到了 here .总结一下这个答案:当遍历历史(也就是点击向上箭头)时,删除重复条目很有帮助,这样您就不会多次滚动相同的命令,这是通过 $HISTCONTROL=ignoreboth:erasedups 完成的
。
在 Python 解释器(或 iPython,特别是)中是否有任何等效项?我安装了 readline
,感觉这是一个很好的起点,但没有明显解决问题的结果,我还以为这是内置在某个地方的。
最佳答案
通过深入研究 IPython,筛选解释不清和/或弃用的文档,我拼凑出一个似乎工作正常的解决方案,但我确信它不是最佳的,原因有很多,即:
history
数据库上运行一个 GROUP BY
查询history
,但忽略 output_history
和 sessions
表我将以下内容放入 $HOME/.ipython/profile_default/startup
内的文件中(我将其命名为 dedupe_history.py
,但名称无关紧要):
import IPython
import IPython.core.history as H
## spews a UserWarning about locate_profile() ... seems safe to ignore
HISTORY = H.HistoryAccessor()
def dedupe_history():
query = ("DELETE FROM history WHERE rowid NOT IN "
"(SELECT MAX(rowid) FROM history GROUP BY source)")
db = HISTORY.db
db.execute(query)
db.commit()
def set_pre_run_cell_event():
IPython.get_ipython().events.register("pre_run_cell", dedupe_history)
## dedupe history at start of new session - maybe that's sufficient, YMMV
dedupe_history()
## run dedupe history every time you run a command
set_pre_run_cell_event()
关于Python 相当于 ignoreboth :erasedups,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42371085/
我正在通过 Anaconda、Mac Sierra、iTerm 和 $SHELL=bash 运行 iPython (Jupyter) - 如果我错过了任何有用的设置细节,请告诉我. 我喜欢 bash
我是一名优秀的程序员,十分优秀!