How to print to stdout from Python script with .pyw extension?
You can tell wxPython's App instance to redirect too. Just set the "redirect" parameter to True:
app = wx.App(True)
Another solution would be to use Python's logging module instead of relying on printing strings to stdout. Using that, you can log to a file or to various web protocols, among others. See the documentation for full details: http://docs.python.org/library/logging.html
There's also a good introductory tutorial here: http://www.doughellmann.com/PyMOTW/logging/
I finally solved my problem with some kind of a nasty trick. I get the help information from argparse like that:
class Parser(object): def __init__(self): [...init argparser...] self.help = "" self.__argparser.print_help(self) def write(self, message): self.help += message
Then I just show the help information in the about dialog.
I would still prefer to re-enable sys.stdout
, but this works for now.Thanks to all suggestions!