This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Overriding code.InteractiveConsole.write does not work
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: r.david.murray, tebeka
Priority: normal Keywords:

Created on 2011-06-24 22:45 by tebeka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg138998 - (view) Author: Miki Tebeka (tebeka) * Date: 2011-06-24 22:45
Consider the following code:
    import code

    class Console(code.InteractiveConsole):
        def write(self, data):
            print("DATA: {0}".format(data))

    c = Console()
    c.interact()

Then enter "1" at the prompt. The output will be 1 (and not DATA: 1).
If you create an error (such as 1/0), then the error lines will be prefixed by DATA.
msg139000 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2011-06-24 23:15
That's correct.  The write method is for writing to stderr, and by implication is called only for errors.  Not, I think, the most obvious name that could have been chosen for the method, but it does seem to be doing what it is documented to do in your example.
msg139003 - (view) Author: Miki Tebeka (tebeka) * Date: 2011-06-24 23:53
I'm trying to read/write data from a socket. Does this mean I need to roll up my own Interpreter? (e.g. no way to override writing to stdout?)

Since this is the expected behaviour, will close this one.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56611
2011-06-25 04:49:07r.david.murraysetstatus: open -> closed
2011-06-24 23:53:09tebekasetstatus: closed -> open

messages: + msg139003
2011-06-24 23:15:52r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg139000

resolution: not a bug
stage: resolved
2011-06-24 22:45:07tebekacreate