[Biopython-dev] [Biopython - Bug #3382] (New) Bio.PDB.PDBList.retrieve_pdb_file() fails for Python3
redmine at redmine.open-bio.org
redmine at redmine.open-bio.org
Wed Sep 5 03:19:53 UTC 2012
Issue #3382 has been reported by Alexander Campbell.
----------------------------------------
Bug #3382: Bio.PDB.PDBList.retrieve_pdb_file() fails for Python3
https://redmine.open-bio.org/issues/3382
Author: Alexander Campbell
Status: New
Priority: Normal
Assignee:
Category:
Target version:
URL:
At present, calling @Bio.PDB.PDBList.retrieve_pdb_file()@ on any PDB ID will fail, giving the following traceback:
<pre>
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-3-4ecf112b58e0> in <module>()
----> 1 pdbl.retrieve_pdb_file('1FAT')
/usr/lib64/python3.2/site-packages/Bio/PDB/PDBList.py in retrieve_pdb_file(self, pdb_code, obsolete, compression, uncompress, pdir)
245 gz = gzip.open(filename, 'rb')
246 out = open(final_file, 'wb')
--> 247 out.writelines(gz.read())
248 gz.close()
249 out.close()
TypeError: 'int' does not support the buffer interface
</pre>
This occurs because in Python3 a file opened in binary mode will return type @bytes@ for @read()@, or a list of type @bytes@ objects for @readlines()@. The @writelines()@ method expects an iterable where each element is of type @str at . This worked in Python2 as a @str@ can be viewed as a sequence of @str@ objects, and so line 247 effectively wrote one character at a time for the single @str@ yielded by @read()@. In Python3 iterating over a @bytes@ yields @int@ objects, leading to the TypeError.
This issue can be fixed by changing line 247's call to @writelines()@ to just @write()@. This does not break functionality in Python2, according to my testing with Python 3.2.3 and 2.7.3 on Fedora 17.
There are 4 more instances of @writelines()@ calls in the codebase, but in each of those cases the argument is a list or generator of @str@ or @bytes@ objects, as I don't think they will raise an error. I haven't tested them though.
----------------------------------------
You have received this notification because this email was added to the New Issue Alert plugin
--
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here and login: http://redmine.open-bio.org
More information about the Biopython-dev
mailing list