pycifrw icon indicating copy to clipboard operation
pycifrw copied to clipboard

`CifFile.WriteOut()` unavoidably prints to stdout

Open kalekundert opened this issue 1 year ago • 2 comments

Here's a minimal example:

>>> from CifFile import CifFile, CifBlock
>>> cf['9xyz'] = CifBlock()
>>> x = cf.WriteOut()
Writing 9xyz, <CifFile.CifFile_module.CifBlock object at 0x71f505f7e620>
All blocks output.

If I want to control the output my program shows to the user, this is pretty annoying behavior. At the very least, I think there should be a way to silence these messages (e.g. cf.WriteOut(verbose=False)). But really, I think they should just be removed.

Looking at the source code, I see that there are a few other messages that get printed when something unexpected happens. I don't have as much issue with these, since they might help catch what would otherwise be silent errors. In a perfect world, though, these messages would probably go through the logging system.

I did try to make a PR for this, since it's a pretty small issue, but I couldn't figure out how to install the library from source. I've also never encountered *.nw files before, so I wasn't really sure if I making the right changes. If you can give me some pointers about these issues, though, I'd still be happy to make a PR.

kalekundert avatar Jan 31 '24 01:01 kalekundert

Thanks for this suggestion. I can make the change to the .nw file. nw is noweb, a now no-longer maintained literate programming approach which does not run on Windows, it seems.

jamesrhester avatar Feb 01 '24 04:02 jamesrhester

I've commented out the offending lines in StarFile.nw.

jamesrhester avatar Feb 01 '24 04:02 jamesrhester