[Tutor] Maybe advanced pexpect question?

mwalsh mwalsh at mwalsh.org
Sun Mar 23 20:00:53 CET 2008

Kent Johnson wrote:
> Nathan McBride wrote:
>> I've used pexpect for a few projects and love it.  Basically pexpect
>> lets you spawn a program and interact with it from code like you
>> yourself were running it in a console.  How would you send the ctrl key?
> I don't use pexpect, so I am guessing...
> The ctrl key by itself is not a character so you can't send that. ctrl-C 
> is a character that is represented in a string as \x03. I expect you 
> would send a control character with sendline(), for example to sent 
> ctrl-C try
>    child.sendline ('\x03')

In recent versions of pexpect (I'm looking at 2.3), 'spawn' objects 
include a sendcontrol  method which does almost exactly that for cntl-c, 
with send instead of sendline.

> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list