[英]How to interpret .py files as jupyter notebooks
I am using an online jupyter notebook that is somehow configured to read all.py files as jupyter notebook files:我正在使用一个在线 jupyter notebook,它以某种方式配置为将 all.py 文件作为 jupyter notebook 文件读取:
I am a big fan of this setup and would like to use it everywhere.我是这个设置的忠实粉丝,并且想在任何地方使用它。 On my own jupyter installation however, .py files are just interpreted as test files and are not by default loaded into jupyter cells.
然而,在我自己的 jupyter 安装中,.py 文件仅被解释为测试文件,默认情况下不会加载到 jupyter 单元中。 How can I achieve the same configuration for my jupyter notebook?
如何为我的 jupyter notebook 实现相同的配置?
That's not exactly what you asked, but you can achieve something close to that by using the magic %load FILE.py
in a new jupyter notebook.这不完全是您所要求的,但您可以通过在新的 jupyter 笔记本中使用魔法
%load FILE.py
来实现与此接近的目标。
%load FILE.py
will copy the contents of FILE.py
in the current cell upon executing it. %load FILE.py
将在执行时将FILE.py
的内容复制到当前单元格中。
You use the python code in your Jupyter Notebook by just pasting the whole code in a cell OR:您只需将整个代码粘贴到单元格中,即可在 Jupyter Notebook 中使用 python 代码,或者:
%load pythonfile.py
to load code from a file (not necessarily.py files) into a jupyter notebook cell; %load pythonfile.py
将文件(不一定是 .py 文件)中的代码加载到 jupyter notebook 单元中;
%run pythonfile.py
in order to execute the file instead of loading it (outputs whatever that file outputs). %run pythonfile.py
以执行文件而不是加载它(输出该文件输出的任何内容)。
Also, pythonfile.py should exist in the cd
or you can use its full path.此外,pythonfile.py 应该存在于
cd
中,或者您可以使用其完整路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.