How to do...?

Quinn Dunkan quinn at
Fri Nov 3 21:15:42 CET 2000

On Fri, 3 Nov 2000 19:22:30 +0100, Guy Van Rentergem
<guy.van.rentergem at> wrote:
>Hello people,
>How can I put characters in the keyboard buffer without typing anything?

>From within python you colud do something like:

class PushFile:
    def __init__(self, fp):
        self.fp = fp
    def readline(self):
        if self.pushback:
            return self.pushback.pop()
            return self.fp.readline()
    def push(self, line):

and replace the file you're reading from with PushFile.  This can be handy for
automatically testing interactive programs.

If you want to control an external program's keyboard input, see the expect

More information about the Python-list mailing list