我有一个用Python编写的基于GUI(TraitsUI/PyQt/Envisage)的应用程序.我想生成一个IPython Notebook,其中我公开了一个小API和一些对象.这些对象包括SQLAlchemy会话和一堆SQLAlchemy模型.
我看了很多,但我找不到任何这方面的例子.我可以开一个笔记本了:
from IPython.frontend.html.notebook import notebookapp
app = notebookapp.NotebookApp.instance()
app.initialize()
app.start()
Run Code Online (Sandbox Code Playgroud)
并且运行良好(虽然我更喜欢'start'是非阻塞的...我假设我可以在另一个线程中执行它,如果需要的话),但我不能改变名称空间.
我也找到了这样的例子:
from IPython.zmq.ipkernel import IPKernelApp
namespace = dict(z=1010)
kapp = IPKernelApp.instance()
kapp.initialize()
# Update the ns we want with special variables auto-created by the kernel
namespace.update(kapp.shell.user_ns)
# Now set the kernel's ns to be ours
kapp.shell.user_ns = namespace
kapp.start()
Run Code Online (Sandbox Code Playgroud)
但我不确定如何从这里实际打开笔记本.
有人有什么建议吗?
谢谢!
>>> import IPython
>>> z=1010
>>> IPython.embed()
Python 3.5.2 (default, Oct 8 2019, 13:06:37)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: z
Out[1]: 1010
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1064 次 |
| 最近记录: |