[Biopython] Print statements vs functions (Python 2 vs 3)
Peter Cock
p.j.a.cock at googlemail.com
Sat Sep 7 11:41:53 UTC 2013
Dear Biopythoneers,
As you will be aware, with our recent release of Biopython 1.62
we now officially support Python 3 for the first time (specifically
Python 3.3 - we don't recommend 3.0, 3.1 or 3.2 here), while
continuing to support Python 2 as well.
Currently all our documentation is written assuming Python 2,
but with some small changes most things can be written to
work under both variants. The most visible change is how to
print things, and that happens a lot in our examples.
I would like us to switch to using the Python 3 style print
function in our documentation (including the Tutorial and
the docstrings embedded in the code as help text).
In the simplest case, this Python 2 only code:
>>> print variable
would be changed to this using Python 3 style:
>>> print(variable)
Luckily that will also work on Python 2 as well. For more
complicated examples to use the print function under
Python 2 you must add this import line to the start of
your file:
>>> from __future__ import print_function
For example, this Python 2 only example:
>>> print "Two plus two is", 4
becomes:
>>> from __future__ import print_function # at start
>>> ...
>>> print("Two plus two is", 4)
or more elegantly,
>>> print("Two plus two is %i" % 4)
Would anyone object to us using the print function style
in the Biopython documentation?
I'm particularly keen to hear from beginners - as this
is potentially confusing.
Thanks,
Peter.
More information about the Biopython
mailing list