[英]IPython Notebook: %run magic on non-python file types
From in the notebook, it's easy to run an external python module with %run
. 在笔记本中,使用
%run
外部python模块很容易。 For example, if I wanted to run foo.py: 例如,如果我想运行foo.py:
%run foo
But how does one run a file not ending in .py
? 但是,如何运行一个不以
.py
结尾的文件? For example, if I had a bash script, bar
. 例如,如果我有一个bash脚本,则为
bar
。 When I try: 当我尝试:
%run bar
ERROR: File `u'$bar.py'` not found.
A while back, someone showed me how to pass the filename so that %run
doesn't append the .py suffix, but I can't dig it up! 不久前,有人向我展示了如何传递文件名,以便
%run
不会附加.py后缀,但我无法对其进行挖掘!
Thanks 谢谢
Thanks for the comments. 感谢您的评论。 To address why I'd like to do something like this, we are distributing an assignment in the IPython notebook for students in an intro programming class, and want them to use
nbconvert
to submit it as an HTML file. 为了解决为什么我想做这样的事情,我们正在IPython笔记本中为一个入门编程班的学生分配作业,并希望他们使用
nbconvert
将其提交为HTML文件。 Many of them use windows, and are using Canopy as their Python distribution. 其中许多使用Windows,并且使用Canopy作为其Python发行版。 To "open a terminal, cd to the working directory and running nbconvert" would be difficult, especially if nbconvert is not in their environmental variables.
要“打开终端,使用cd进入工作目录并运行nbconvert”将非常困难,尤其是如果nbconvert不在其环境变量中时。 It would be much easier on us to just have a one-liner that they can run from within the notebook environment.
对我们来说,只有一个衬套可以在笔记本环境中运行会容易得多。
Yes, the %%bash magic worked fine. 是的,%% bash魔术效果很好。 Sorry I didn't catch this.
对不起,我没听懂。
%%bash
ipython nbconvert --to html worldmap_notebook.ipynb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.