Pexpect无法做到的期望是什么? [英] What can Expect do that Pexpect can not do?

查看:50
本文介绍了Pexpect无法做到的期望是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑开始使用Pexpect.在Pexpects主页上,我发现了这一点:

I am considering to start using Pexpect. On Pexpects homepage I find this:

问:为什么不只使用Expect?

Q: Why not just use Expect?

A:我爱它.这很棒.我已将我救出一些真正的果酱,但我想要一些东西可以满足我90%的需求预计;是尺寸的10%;并允许我改为用Python编写代码的TCL.Pexpect几乎没有那么大符合预期,但是Pexpect会做所有的事情我曾经用过Expect.

A: I love it. It's great. I has bailed me out of some real jams, but I wanted something that would do 90% of what I need from Expect; be 10% of the size; and allow me to write my code in Python instead of TCL. Pexpect is not nearly as big as Expect, but Pexpect does everything I have ever used Expect for.

Pexpect与Expect之间有10%的差异.所以我的问题是10%的差异是多少.Expect可以做Pexpect无法做的事情.

There is a 10% difference between Pexpect and Expect. So my question is what is this 10% difference. What is it that Expect can do that Pexpect can't.

推荐答案

这个问题(" Pexpect无法做到的Expect可以做什么")有点误导.这并不是说Pexpect不能做Expect可以做的事情;正是Expect有了很多额外的支持,使这种编程变得更加容易.

That question ("What is it that Expect can do that Pexpect can't") is a bit misleading. It's not that Pexpect can't do things that Expect can; it's that Expect has a lot of extra support to make this kind of programming easier.

以一个示例为例,使用interact命令,该命令使用户可以直接与生成的进程进行交互.在Pexpect中,这就是所有交互作用.(正如您所说,这可能足以满足您的需求.)相反,Expect的交互支持在交互过程中检测模式,将多个衍生过程挂钩在一起等.当然,您可以自己编写代码来完成所有这些工作.但是您的代码会更长-有时会更长,因为您本质上必须重写自己的交互,必须调试它,等等.实际上,您可能已经遇到了这些情况,但没有意识到等价的期望代码.

As an example, take the interact command which lets the user interact directly with the spawned process. In Pexpect, that's all interact does. (And that may be sufficient for your needs, as you say.) In contrast, Expect's interact has support for detecting patterns during an interact, hooking together multiple spawned processes, etc. Of course, you can do all this by coding it yourself. But your code will be longer - sometimes a lot longer because you'll essentially have to rewrite your own interact, you'll have to debug it, etc. In fact, you may have encountered these situations already but not realized how much simpler the equivalent Expect code would be.

当然,您对Python的偏好可能会抵消额外的支持.:-P

Of course, the extra support may be more than offset by your preference for Python. :-P

这篇关于Pexpect无法做到的期望是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆