Hi Steve,
Try replacing “w+” with “wb+” to open the file as a binary stream.
Cheers,
p.
> On 2 Sep 2018, at 16:13, Sharky El Sharko <[email protected]> wrote:
>
> Hi,
>
> Please can someone tell me why I am getting an error writing a gzipped sdf,
> and how to fix it. I am running python 3.6.5 with the latest RDKit
> (2018.03.3), and the following code:
>
> #!/usr/bin/env python
>
> import gzip
> from rdkit import Chem
>
> outfZ = gzip.open('out02.sdf.gz', 'w+')
> writer = Chem.SDWriter(outfZ)
> m1 = Chem.MolFromSmiles('Cc1ccccc1')
> m2 = Chem.MolFromSmiles('Nc1ccccc1')
> list_of_mols = [m1, m2]
> for mol in list_of_mols:
> writer.write(mol)
> writer.close()
> outfZ.close()
>
> gives the following error:
>
> Traceback (most recent call last):
> File "./exampleGzip02.py", line 12, in <module>
> writer.write(mol)
> File "/xxx/yyy/miniconda2/envs/my-rdkit-env/lib/python3.6/gzip.py", line
> 260, in write
> data = memoryview(data)
> TypeError: memoryview: a bytes-like object is required, not 'str'
>
> I tried a few ways to wrestle the mol into a binary format, but without
> success. Can anyone enlighten me, please.
>
>
> Thanks very much.
>
>
> Kind regards,
>
>
> Steve
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss