How to obtain a 'interactive session' of a script?

Fredrik Lundh fredrik at pythonware.com
Sun Sep 18 12:53:57 EDT 2005


Bo Peng wrote:

> This method works fine with only one minor problem. It would stop
> (waiting for user input) at help(str) command. I will have to find a way
> to feed the program with'q' etc.

replacing sys.stdin with something that isn't a TTY will fix this.

here's one way to do it:

    class wrapper:
        def __init__(self, file):
            self.file = file
        def isatty(self):
            return 0
        def __getattr__(self, key):
            return getattr(self.file, key)

    sys.stdin = wrapper(sys.stdin)

</F> 






More information about the Python-list mailing list