
- Jupyter 教程
- Jupyter - 首頁
- IPython
- IPython - 簡介
- IPython - 安裝
- IPython - 開始使用
- 執行和編輯Python指令碼
- IPython - 歷史命令
- IPython - 系統命令
- IPython - 命令列選項
- 動態物件自省
- IPython - I/O快取
- 將IPython設定為預設Python環境
- 匯入Python Shell程式碼
- IPython - 嵌入IPython
- IPython - 魔術命令
- Jupyter
- Jupyter專案 - 概述
- Jupyter Notebook - 簡介
- 線上使用Jupyter
- 安裝和開始使用
- Jupyter Notebook - 儀表盤
- Jupyter Notebook - 使用者介面
- Jupyter Notebook - 單元格型別
- Jupyter Notebook - 編輯
- Jupyter Notebook - Markdown單元格
- 單元格魔法函式
- Jupyter Notebook - 繪圖
- 轉換Notebook
- Jupyter Notebook - IPyWidgets
- QtConsole
- QtConsole - 開始使用
- QtConsole - 多行編輯
- QtConsole - 內聯圖形
- QtConsole - 儲存為Html
- QtConsole - 多個控制檯
- 連線到Jupyter Notebook
- 使用github和nbviewer
- JupyterLab
- JupyterLab - 概述
- 安裝和開始使用
- JupyterLab - 介面
- JupyterLab - 安裝R核心
- Jupyter資源
- Jupyter - 快速指南
- Jupyter - 有用資源
- Jupyter - 討論
嵌入IPython
IPython模組的embed()函式可以將IPython嵌入到你的Python程式碼的名稱空間中。這樣你就可以在預設的Python環境中利用IPython的功能,例如物件自省和Tab鍵補全。

在嵌入之前存在於全域性名稱空間中的Python物件,將可用於IPython。

如果在IPython中形成了新的物件或修改了之前的物件,則在退出IPython後,它們將自動可用於預設環境。嵌入的IPython Shell不會改變先前程式碼或物件的狀態。
但是,如果IPython嵌入在區域性名稱空間中(例如在函式內部),則一旦關閉,其中的物件將不可用。這裡,我們定義了一個函式add()。在add()中,我們呼叫IPython並聲明瞭一個變數。如果我們嘗試在關閉IPython後訪問該變數,則會引發NameError異常。

廣告