[Biopython] Print statements vs functions (Python 2 vs 3)
Peter Cock
p.j.a.cock at googlemail.com
Mon Sep 9 11:02:59 EDT 2013
On Mon, Sep 9, 2013 at 3:58 PM, Carlos Borroto <carlos.borroto at gmail.com> wrote:
> 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
I'm not aware of any plans to withdraw the old string % operator
in Python 3, although the implication from PEP3101 is that might
eventually happen.
http://www.python.org/dev/peps/pep-3101/
Peter
More information about the Biopython
mailing list