简体   繁体   English

IPython Notebook:代码重用

[英]IPython Notebook: code reuse

Is it possible to plug IPython notebook into existing Python project and to be able to reuse some of the existing code w/o copy-pasting it into a notebook? 是否可以将IPython笔记本插入现有的Python项目中,并能够重用一些现有的代码,而无需将其复制粘贴到笔记本中?

I am looking for a way to use IPython Notebooks as a part of a large Python project to quickly test hypothesis and to analyze data on the spot. 我正在寻找一种方法来使用IPython笔记本作为大型Python项目的一部分,以快速测试假设并在现场分析数据。

PS It would also be nice to be able to import Python files into a Notebook. PS能够将Python文件导入Notebook也很好。 Is it possible? 可能吗?

I see this is an old question, but I want to answer it if someone still looks it up. 我看到这是一个老问题,但如果有人还在查找,我想回答。

PS It would also be nice to be able to import Python files into a Notebook. PS能够将Python文件导入Notebook也很好。 Is it possible? 可能吗?

You can import any python script ( filexy.py ) from the same folder as your notebook by simply stating import filexy . 您可以通过简单地说明import filexy从与笔记本相同的文件夹中导入任何python脚本( filexy.py )。

Relating to that, I'd suggest that you define functions for your most reused code bits and gather them in a library ( filexy.py ) that you import in your notebook. 与此相关,我建议您为最常用的代码位定义函数,并将它们收集到您在笔记本中导入的库( filexy.py )中。 Use the notebook as a short, clean, "working-desk" and your filexy.py library as the "toolbox". 将笔记本用作简短,干净的“工作台”,将filexy.py库用作“工具箱”。

That way you can also solve: 那样你也可以解决:

I am looking for a way to use IPython Notebooks as a part of a large Python project to quickly test hypothesis and to analyze data on the spot. 我正在寻找一种方法来使用IPython笔记本作为大型Python项目的一部分,以快速测试假设并在现场分析数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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