[Biopython-dev] Using .format() method of strings in Biopython?
Peter Cock
p.j.a.cock at googlemail.com
Tue Oct 13 11:03:03 UTC 2015
Dear Biopythoneers,
As part of https://github.com/biopython/biopython/pull/635
Carlos is suggesting replacing some of the % string formatting
(which is like the C sprintf function) with the Python string .format()
method.
e.g.
"Codon '%s' is invalid" % codon
becomes:
"Codon '{0}' is invalid".format(codon)
https://pyformat.info/
https://docs.python.org/2/library/string.html#formatstrings
https://docs.python.org/2/library/stdtypes.html#string-formatting
Note the later says the following about the .format method:
"This method of string formatting is the new standard in Python 3"
We don't have anything explicit about this on our current short
coding conventions entry on the wiki:
http://biopython.org/wiki/Contributing#Coding_conventions
Right now usage of the format method is rare (e.g. Bio.codonalign
and Bio.motifs.jaspar)
Should we be encouraging more use of the format method?
Is there a more explicit PEP standard we can cite for this
preference?
Peter
More information about the Biopython-dev
mailing list