如何将Stdin发送到Ipython?

发布于 2025-02-14 01:13:48 字数 616 浏览 0 评论 0原文

我在尝试通过STDIN将数据发送到Ipython时很难,似乎EOF被解释为Ipython的退出命令吗?

示例:

echo'“ hello”'| ipython

Python 3.9.2 (default, Feb 28 2021, 17:03:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: Out[1]: 'hello'

In [2]: Do you really want to exit ([y]/n)?

并且该过程在没有我做其他任何事情的情况下退出。

是否有要设置的参数?


编辑:为了使上下文更清晰,我想做的实际情况如下:

program1 | ipython -i -c“%运行脚本”

program1将输出某些内容(json),而ipython会运行一个将东西加载到我可以使用的东西中的脚本,然后让我进入我可以玩的ipython解释器与它。

I'm having trouble trying to send data through stdin to IPython, it seems that EOF is interpreted as an exit command for ipython ?

Example:

echo '"hello"' |ipython

Python 3.9.2 (default, Feb 28 2021, 17:03:44)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: Out[1]: 'hello'

In [2]: Do you really want to exit ([y]/n)?

And the process quits without me doing anything else.

Is there a parameter to set or something ?


Edit: To make the context clearer, the real scenario where I want to do this is the following:

program1 | ipython -i -c "%run script"

program1 would output something (a json), and ipython would run a script that load the thing into something I can use, then leave me to a IPython interpreter where I can play with it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铜锣湾横着走 2025-02-21 01:13:48

与评论相同。您的问题还不清楚。

也许将某些python命令送到python interter?

尝试此

$ (echo 'a=123' && cat ) | ipython -i
Python 3.6.9 (default, Mar 15 2022, 13:55:28)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.3 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
In [2]: print(a)
123

尝试将执行a = 123,并将Python进入相互作用模式,该模式将您的键盘输入输入

Same as comment. your question is quite unclear.

Maybe pipe some python command to a python interperter?

try this

$ (echo 'a=123' && cat ) | ipython -i
Python 3.6.9 (default, Mar 15 2022, 13:55:28)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.16.3 -- An enhanced Interactive Python. Type '?' for help.

In [1]:
In [2]: print(a)
123

this will execute a=123 and make python into interative mode which take your keyboard input

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文