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

Make mrcfile.validate silent #66

Open
cdienem opened this issue Feb 7, 2025 · 1 comment
Open

Make mrcfile.validate silent #66

cdienem opened this issue Feb 7, 2025 · 1 comment

Comments

@cdienem
Copy link

cdienem commented Feb 7, 2025

Hi.

I have a small suggestion for improvement. Would it be possible to make the printed output of mrcfile.validate() optional in case I am just interested in a bolean return value?

Best and thanks,
Chris

@colinpalmer
Copy link
Member

That should be easy enough so I will certainly consider adding it next time I make an mrcfile release.

In the meantime, Python's contextlib makes it quite easy to capture the print output if you need to:

import contextlib
import io
import mrcfile
with contextlib.redirect_stdout(io.StringIO()):
    result = mrcfile.validate('file.mrc')

If the files are badly invalid you might also get warnings on stderr, which you can suppress similarly with contextlib.redirect_stderr or Python's standard warning controls.

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

No branches or pull requests

2 participants