As a style note,
On Jan 26, 2012, at 11:00 AM, Greg Landrum wrote:
> To answer your question, the following bit of code works:
>
> f = gzip.open('output.sdf.gz','w+')
> w = Chem.SDWriter(f)
> for m in ms: w.write(m)
> w.flush()
> f.flush()
> w=None
> f=None
If you are running with Python 2.7 then a context-mangager solution might be
cleaner:
with gzip.open('output.sdf.gz','w+') as f:
w = Chem.SDWriter(f)
for m in ms: w.write(m)
w.flush()
w = None
Since SDWriter doesn't implement a context manager, but does implement close()
(and Greg says that close() does the needed flush()), then another solution is:
import contextlib
with gzip.open('output.sdf.gz','w+') as f:
with contextlib.closing(Chem.SDWriter(f)) as w:
for m in ms:
w.write(m)
If the SDWriter were to implement the context manager interface for file-like
objects, then the interface would be even simpler:
with gzip.open('output.sdf.gz','w+') as f:
with Chem.SDWriter(f) as w:
for m in ms:
w.write(m)
Consider that a request. :)
Andrew
[email protected]
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss