wptools icon indicating copy to clipboard operation
wptools copied to clipboard

do not print results from get_parse to stderr

Open boompig opened this issue 4 years ago • 7 comments

Currently get_parse always outputs results to stderr. Is there a way to run this function silently? This is especially annoying when crawling or running in Jupyter notebook.

boompig avatar May 26 '20 18:05 boompig

Yes, try page = wptools.page(silent=True), as mentioned in our Usage wiki page.

siznax avatar May 26 '20 22:05 siznax

thanks for the quick response. consider making this the default?

boompig avatar May 27 '20 14:05 boompig

Hmm. That might be a good idea. Anyone else have a preference? (thinking about it)

siznax avatar May 27 '20 18:05 siznax

While on the subject, is there a way for errors not to be printed as well, while using "silent=True"? I'm searching for pages by name, and sometimes they don't exist. I handle it, but the error of not finding the page is still showing up.

TsUNaMyWaVe avatar Jan 26 '21 17:01 TsUNaMyWaVe

Yes @TsUNaMyWaVe, try catching the exception raised, probably LookupError. Something like this?

try:
    <your code>
except LookupError:
    pass

siznax avatar Jan 26 '21 18:01 siznax

@siznax thanks! I actually found a little bit cleaner solution:

with contextlib.redirect_stderr(io.StringIO()):
                <your code>

But I think adding this option as part of the tool could be a good improvement as well. By either adding it to the "silent" argument, or adding an additional argument for error printing.

TsUNaMyWaVe avatar Jan 26 '21 18:01 TsUNaMyWaVe

@TsUNaMyWaVe thanks for the suggestion. In the case of an error, redirecting to stderr seems appropriate. Still trying to decide if "silent by default" is best. Any opinion on that?

siznax avatar Jan 26 '21 20:01 siznax