python - 从脚本以编程方式调用 Jupyter Notebook 魔术命令
问题描述
您可以从脚本中调用 Jupyter 中的魔术命令,如下所示:
ipython = get_ipython()
mgc = ipython.run_line_magic
mgc(magic_name = "my_magic_command", line="line_to_call")
但是,如果我尝试使用 HTML 魔术命令执行此操作:
mgc(magic_name = "%%html", line="<iframe src='my_url' width='100%' height='400'></iframe>")
我收到以下错误:
UsageError: Line magic function `%%%html` not found.
让我觉得我应该删除 % 之一:
mgc(magic_name = "%html", line="<iframe src='my_url' width='100%' height='400'>")
UsageError: Line magic function `%%html` not found.
...或删除两个 %:
mgc(magic_name = "html", line="<iframe src='my_url' width='100%' height='400'>")
UsageError: Line magic function `%html` not found (But cell magic `%%html` exists, did you mean that instead?).
这可能与import 的顺序有关,但我似乎无法解决这个问题。
解决方案
推荐阅读
- python - Keras 模型输入的形状(尺寸)和类型错误
- google-app-engine - gcloud 应用程序部署在 AppEngine 标准环境中因超时而失败
- karate - 空手道 - 如何在被调用的功能中配置 afterScenario 挂钩?
- graphql - 解析 GraphQL 查询时出现语法错误。输入意外结束
- perl - 将变量从 shell 脚本传递到 Perl 脚本
- c# - 图是循环搜索
- python - 将字典数组的前 2 个元素转换为元组
- java - 获取认证密钥,小米手环 5
- c++ - 创建单个掩码以检查位是否已设置、取消设置或接受
- android - 更改 MaterialButtonToggleGroup 的背景颜色