简体   繁体   中英

How do I run a command in a Jupyter notebook?

In a notebook I have the following in a cell:

   cwd = os.getcwd()
   run cwd + "/plot_data.py"

I get the error:

ERROR:root:File `'cwd.py'` not found.

Apparently, run thinks I am trying to run a python file "cwd.py" with the options "+" and "plot_data.py".

Actually I am trying to run a file plot_data.py located in cwd

Create the full file name, and pass it to run with the $ prefix:

file = cwd + "/plot_data.py"
run $file

In

run cwd + "/plot_data.py"

cwd is the file parameter, to be run, and '+' and "/plot..." are arguments that get passed to it. This isn't a Python expression (which would preform the string join).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM