Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not print results from get_parse to stderr #153

Open
boompig opened this issue May 26, 2020 · 7 comments
Open

do not print results from get_parse to stderr #153

boompig opened this issue May 26, 2020 · 7 comments
Assignees

Comments

@boompig
Copy link

boompig commented May 26, 2020

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.

@siznax
Copy link
Owner

siznax commented May 26, 2020

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

@boompig boompig closed this as completed May 27, 2020
@boompig
Copy link
Author

boompig commented May 27, 2020

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

@siznax
Copy link
Owner

siznax commented May 27, 2020

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

@siznax siznax reopened this May 27, 2020
@siznax siznax self-assigned this May 27, 2020
@TsUNaMyWaVe
Copy link

TsUNaMyWaVe commented Jan 26, 2021

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.

@siznax
Copy link
Owner

siznax commented Jan 26, 2021

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

try:
    <your code>
except LookupError:
    pass

@TsUNaMyWaVe
Copy link

TsUNaMyWaVe commented Jan 26, 2021

@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.

@siznax
Copy link
Owner

siznax commented Jan 26, 2021

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants