[英]How to get the current ipython session number for use in %history
在 ipython 中, %history
魔術命令顯示當前會話的歷史記錄。 %history
接受一個可選的range
參數,指定會話和/或行以從中提取歷史記錄。 我想知道如何使用range
規定為<session_number>/<lines>
,例如, %history 243/1-5
將顯示從會話243的歷史第1-5行。
%history
遍歷所有會話)?我不知道如何在不瀏覽所有歷史記錄的情況下獲得所有過去的會話編號。 但這里是你如何獲得當前和上一個。
>>> ip=get_ipython()
>>> hm =ip.history_manager
>>> hm.get_session_info()
Out: (281, datetime.datetime(2020, 3, 21, 9, 13, 51, 939379), None, None, '')
>>> hm.get_last_session_id()
Out: 281
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.