Could Emacs be rewritten in Python?

Patrick K. O'Brien pobrien at orbtech.com
Wed Apr 16 11:52:55 EDT 2003


Michael Hudson <mwh at python.net> writes:

> Carl Banks <imbosol-1050441179 at aerojockey.com> writes:
> 
> > First, you're basing it on a bad example.  Rebinding sys.stdout is bad
> > programming, period.
> 
> Whoah there!  Says who?  Would you like to try using IDLE or any other
> IDE without binding sys.stdout?

Or how about one that includes a Python shell (like PyCrust) where the
user can rebind any of stdin, stdout, stderr, by entering the
appropriate code at the interactive prompt, but the shell itself needs
to keep on working?  If rebinding sys.stdout is bad, I'm happy to say
that PyCrust is bad, really bad.  ;-)

    def runsource(self, source):
        """Compile and run source code in the interpreter."""
        stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr
        sys.stdin, sys.stdout, sys.stderr = \
                   self.stdin, self.stdout, self.stderr
        more = InteractiveInterpreter.runsource(self, source)
        # If sys.std* is still what we set it to, then restore it.
        # But, if the executed source changed sys.std*, assume it was
        # meant to be changed and leave it. Power to the people.
        if sys.stdin == self.stdin:
            sys.stdin = stdin
        if sys.stdout == self.stdout:
            sys.stdout = stdout
        if sys.stderr == self.stderr:
            sys.stderr = stderr
        return more

-- 
Patrick K. O'Brien
Orbtech      http://www.orbtech.com/web/pobrien
-----------------------------------------------
"Your source for Python programming expertise."
-----------------------------------------------




More information about the Python-list mailing list