[Biopython-dev] [Bug 2561] SeqRecord format method to get a string in a given file format

bugzilla-daemon at portal.open-bio.org bugzilla-daemon at portal.open-bio.org
Sat Aug 2 12:06:23 EDT 2008


http://bugzilla.open-bio.org/show_bug.cgi?id=2561





------- Comment #11 from jflatow at northwestern.edu  2008-08-02 12:06 EST -------
In re-reading the PEP, the string method `.format` does not just call the 
`.__format__` method, they actually have two different signatures:

def format(self, *args, **kwargs):
 ...
and

def __format__(self, format_spec):
 ...

I still think its reasonable that *ours* should just call `.__format__`, like
the builtin will. However, this might suggest that reversing the function calls
s.t. `.format` calls `.__format__` and all the work is done in the latter might
be better. I think `.__format__` is the true underlying mechanism, whose
behavior is specced out explictly in the PEP, while `.format` is really just a
convenience method, whose signature could potentially change to make it even
more convenient. This will also prevent arguments claiming that it is less
efficient to use 'This is my record {0:fasta}'.format(record) than 'This is my
record {0}'.format(record.format('fasta')), though I doubt that's much of an
issue.

One other small point is that for 2.x, string objects and unicode objects are
different and so the PEP suggests that any implementation of the `.__format__`
method should check the type of the format_spec argument to see if its unicode
or string and return the appropriate type. 

(In reply to comment #10)
> Created an attachment (id=982)
 --> (http://bugzilla.open-bio.org/attachment.cgi?id=982&action=view) [details]
> Patch to Bio/SeqRecord.py and Bio/Align/Generic.py (revised)
> 
> Revised patch, using .format() as the method name (with no default), and adding
> the __format__ method too (which defaults to calling __str__ if no format is
> given).
> 
> [Once we settle on the naming, and check this in, I'll also update the unit
> tests to use this new functionality]
> 


-- 
Configure bugmail: http://bugzilla.open-bio.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


More information about the Biopython-dev mailing list