[Biopython] Print statements vs functions (Python 2 vs 3)

Carlos Borroto carlos.borroto at gmail.com
Mon Sep 9 14:58:30 UTC 2013


On Mon, Sep 9, 2013 at 10:49 AM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
> On Mon, Sep 9, 2013 at 3:35 PM, Carlos Borroto <carlos.borroto at gmail.com> wrote:
>> On Sat, Sep 7, 2013 at 7:41 AM, Peter Cock <p.j.a.cock at googlemail.com> wrote:
>>> or more elegantly,
>>>
>>>>>> print("Two plus two is %i" % 4)
>>
>> Shouldn't this be done even more elegantly with something like this:
>>
>>>>> print( "Two plus two is {0:d}".format( 4 ) )
>>
>> --Carlos
>
> Personally I find the % version shorter and clearer, but this
> may reflect my past exposure to C.
>
> Where you have more than a couple of place holders,
> naming them seems a bigger win through.
>
> Peter

I was trying to remember the reason I switched to .format(). I believe
it was for better compatibility with future versions of Python. See
this[1] stackoverflow answer. Is that correct? Is % being phased out?.
I know old habits are hard to kill, but maybe the tutorial should
introduce newcomers to future-proof way of doing things. That way they
won't have to kill one more "old" habit.

[1]http://stackoverflow.com/questions/517355/string-formatting-in-python

--Carlos



More information about the Biopython mailing list