欢迎来到 AI 中文社区(简称 AI 中文社),这里是学习交流 AI 人工智能技术的中文社区。 为了更好的体验,本站推荐使用 Chrome 浏览器。
全部教程·
Python语言·
Jupyter
[目录]
·
IPython 嵌入
Jupyter 教程
IPython 安装
IPython 启动
IPython 运行脚本
IPython 历史命令
IPython 系统命令
IPython 命令行选项
IPython 动态对象自省
IPython IO缓存
IPython 环境变量
IPython shell代码
IPython 嵌入
IPython 魔术命令
Jupyter 项目
Jupyter 笔记本
Jupyter 在线使用
Jupyter 安装与入门
Jupyter 仪表盘
Jupyter 用户界面
Jupyter 单元格类型
Jupyter 编辑
Jupyter Markdown
Jupyter 魔术功能
Jupyter 绘图
Jupyter 转换
Jupyter IPyWidgets
Jupyter QtConsole入门
QtConsole 多行编辑
QtConsole 嵌入式图形
QtConsole 保存为HTML
QtConsole 多个控制台
Jupyter 笔记本连接
Jupyter 笔记本共享
JupyterLab 概述
JupyterLab 安装和入门
JupyterLab 界面
JupyterLab 安装R内核
Jupyter 教程
IPython 安装
IPython 启动
IPython 运行脚本
IPython 历史命令
IPython 系统命令
IPython 命令行选项
IPython 动态对象自省
IPython IO缓存
IPython 环境变量
IPython shell代码
IPython 嵌入
IPython 魔术命令
Jupyter 项目
Jupyter 笔记本
Jupyter 在线使用
Jupyter 安装与入门
Jupyter 仪表盘
Jupyter 用户界面
Jupyter 单元格类型
Jupyter 编辑
Jupyter Markdown
Jupyter 魔术功能
Jupyter 绘图
Jupyter 转换
Jupyter IPyWidgets
Jupyter QtConsole入门
QtConsole 多行编辑
QtConsole 嵌入式图形
QtConsole 保存为HTML
QtConsole 多个控制台
Jupyter 笔记本连接
Jupyter 笔记本共享
JupyterLab 概述
JupyterLab 安装和入门
JupyterLab 界面
JupyterLab 安装R内核
IPython 嵌入
通过 IPython 模块的 embed() 函数,可以将 IPython 嵌入到 Python 代码的命名空间中。因此,您可以在默认的Python环境中利用IPython功能,例如对象自省和制表符完成。

在嵌入之前,存在于全局名称空间中的Python对象将可供IPython使用。

如果在IPython中形成新对象或修改了先前的对象,则退出IPython后它们将自动用于默认环境。嵌入式IPython Shell不会更改早期代码或对象的状态。
但是,如果IPython像函数内部一样嵌入在本地名称空间中,则其内部的对象一旦关闭就将不可用。在这里,我们定义了一个函数add()。在add()内部,我们调用IPython并声明了一个变量。如果在关闭后尝试在IPython中访问变量,则会引发NameError异常。

下一章:IPython 魔术命令
IPython魔术命令:魔术命令或魔术函数是IPython与标准Python shell相比提供的重要增强功能之一。这些魔术命令旨在解决使用Python进行数据分析中的常见问题。实际上,它们控制着IPython本身的行为。在Python语法 ...
AI 中文社