簡體   English   中英

如何獲取當前的 ipython 會話號以在 %history 中使用

[英]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行。

  1. 如何找到與給定搜索字符串匹配的過去會話的會話編號(而不僅僅是使用%history遍歷所有會話)?
  2. 如何找到當前正在運行的 ipython 會話的會話號?

我不知道如何在不瀏覽所有歷史記錄的情況下獲得所有過去的會話編號。 但這里是你如何獲得當前和上一個。

>>> 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM