如何解决pexpect 中的 send() 和 sendline() 有什么区别?
我可以看到发送行有换行符。但是,我无法理解什么时候会使用 child.send()
?
谁能帮助我理解或举例说明 child.send()
和 child.sendline()
之间的区别?
解决方法
sendline()
只是 send()
的一个方便的包装器。如果您不想按 ENTER,则必须使用 send()
。
以下内容来自我系统上的 /usr/local/lib/python3.7/dist-packages/pexpect/pty_spawn.py
:
def sendline(self,s=''):
'''Wraps send(),sending string ``s`` to child process,with
``os.linesep`` automatically appended. Returns number of bytes
written. Only a limited number of bytes may be sent for each
line in the default terminal mode,see docstring of :meth:`send`.
'''
s = self._coerce_send_string(s)
return self.send(s + self.linesep)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。