[BioPython] suggestions for Bio.PDB

thamelry at binf.ku.dk thamelry at binf.ku.dk
Sun Apr 17 13:05:43 EDT 2005


> Catherine Letondal wrote:
>> Would it be possible for the get_structure() method in PDBParser to
>> accept a filehandle, instead of just accepting just a filename?
>
>>     def get_structure(self, id, filename=None, filehandle=None):
>>         """Return the structure.
>
> I've also seen this sort of API done like this
>
>     def get_structure(self, id, infile):
>        if isinstance(infile, basestring):
>          infile = open(infile)
>
> so that there is only one parameter instead of two.

I used:

def get_structure(self, id, file):
    ...
    if type(file)==types.StringType:
            file=open(file)

So there's indeed only one parameter.
If 'file' is not a string it's assumed to have the
interface of a file handle.

-Thomas



More information about the BioPython mailing list