I am using the readline module with Python 2.7.3 with Fedora 17. I do not have this problem with Ubuntu 12.10.
During import readline , an escape char is displayed.
$ python -c 'import readline' |less ESC[?1034h(END)
Usually, when I get an unexpected output like this, I process it by redirecting stdout/stderr to a dummy file descriptor (example below). But this time this method does not work.
import sys class DummyOutput(object): def write(self, string): pass class suppress_output(object): """Context suppressing stdout/stderr output. """ def __init__(self): pass def __enter__(self): sys.stdout = DummyOutput() sys.stderr = DummyOutput() def __exit__(self, *_): sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ if __name__ == '__main__': print 'Begin' with suppress_output():
If you run this snippet in a test.py script, you will see that inside the suppress_output context the print statements are actually suppressed, but not escape char.
$ python test.py |less Begin ESC[?1034hEnd (END)
So here are my two questions:
- How is it possible for this escape character to pass?
- How to suppress it?
python import readline stdout io-redirection
Alex
source share