From in the notebook, it's easy to run an external python module with %run
. For example, if I wanted to run foo.py:
%run foo
But how does one run a file not ending in .py
? For example, if I had a bash script, 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!
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. Many of them use windows, and are using Canopy as their Python distribution. To "open a terminal, cd to the working directory and running nbconvert" would be difficult, especially if nbconvert is not in their environmental variables. It would be much easier on us to just have a one-liner that they can run from within the notebook environment.
Creator of ipython suggests this:
%%bash
. ~/.bashrc
Yes, the %%bash magic worked fine. Sorry I didn't catch this.
%%bash
ipython nbconvert --to html worldmap_notebook.ipynb
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.