jupyter-notebook - IPython REPL 任何地方 : how to share application context with IPython console for future interaction?

标签 jupyter-notebook console ipython interactive read-eval-print-loop

IPython 控制台是一个非常强大的开发工具。它用于一般研究,应用程序和算法开发都作为意义捕捉。

有没有办法将 Python 应用程序的当前上下文与 IPython 控制台连接起来?像 import ipyconsole; ipyconsole.set_interactive_from_here().

这里是更完整的情况。

第一流。 下面是某种正在运行的 python 应用程序,带有初始化的数据库和网络应用程序路由。

class App:
    def __init__(self):
        self.db = DB.new_connection("localhost:27018")
        self.var_A = "Just an example variable"
        
    def run(self):
        self.console = IPythonAppConsole(self) #Console Creation
        self.console.initialize()
        self.kernel = console.start()
        # print(self.kernel.connection_file)
        # << "kernel-12345.json"

    # let the app be some kind of web/flask application 
    @app.route('/items/<item_id>')
    def get_item(self, item_id=0):
        ### GOOD PLACE for
        ### <import ipyconsole; ipyconsole.set_interactive_from_here(self.kernel)> CODE
        item = self.db.find_one({'_id': item_id})
        print(item)
          

第二个交互流程。这是一个有值(value)的目标。

$: ipython console --existing "kernel-12345.json"
<< print(self.db.uri)
>> "localhost:27018"
<< print(item_id)
>> 1234567890

是否有实现这两个流程的常识性方法?也许 pdbipython 内核有某种神奇的组合?


顺便说一句,还有另一种与应用程序通信的交互方式:

  1. 调试。使用 pdb/ipdb/web-pdb 调试应用程序,使用这样的 snipper import pdb; pdb.set_trace() 在代码的任何行中。
  2. 从 Python 代码生成 IPython 笔记本片段。任何地方 pyvt .

今天我在 IPython/shellapp 中寻找答案,kernelapp 源与 Jupyter console 和通过 Redis 共享的动态变量。感谢您提供任何想法!

enter image description here

最佳答案

也许 Flask shell 就是您要找的东西 https://flask.palletsprojects.com/en/1.1.x/shell/

关于jupyter-notebook - IPython REPL 任何地方 : how to share application context with IPython console for future interaction?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66121284/

相关文章:

python - 当所有类名称相似时,如何在selenium python中提取数据?

javascript - 如何恢复已被网站禁用的 console.log() 功能?

python - repl 在网页中,最好的方法是什么?

python - IPython 笔记本中的标准输出与 CLI IPython

IPython 交互式幻灯片?

firefox - console.log 没有显示在我的 Firebug 中

python - matplotlib:从命令行运行 ipython 时在 Web 浏览器中顺序显示绘图

command-prompt - IPython - 单行间距可能吗?

python - Jupyter:禁用重启内核警告

C++清理控制台窗口