KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 unexpected output like this, I handle it using stdout/stderr redirection 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(): # Those two print statements have no effect # but *import readline* prints an escape char print 'Before importing' import readline print 'After importing' # This one will be displayed print 'End' If you run this snippet in a test.py script, you will see that inside the suppress_output context, the print statements are indeed suppressed , but not the 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 get through? How to suppress it?
Tags (comma-separated)
Save Edits
Cancel