<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div id="bloop_customfont" style="margin: 0px; font-size: 13px; font-family: Helvetica, Arial; "><div id="bloop_customfont" style="margin: 0px; ">Sure, a common pattern for a lot of BioPython modules seems to be:</div><div id="bloop_customfont" style="margin: 0px; "><br></div><div id="bloop_customfont" style="font-family: helvetica; margin: 0px; "><div id="bloop_customfont" style="margin: 0px; "><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> # +from __future__ import print_function</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"><br></font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"><br></font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> def foo():</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> """A docstring with print statement.</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"><br></font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> >>> print "foo"</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> foo</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> """</font></div><div id="bloop_customfont" style="margin: 0px; "><span style="font-family: 'Courier New'; "> print "Running foo ...</span><span style="font-family: 'Courier New'; ">"</span></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> # +print("Running foo ...")</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"><br></font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"><br></font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> if __name__ == "__main__":</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> import doctest</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New"> doctest.testmod()</font></div><div style="font-family: Helvetica, Arial; "><br></div></div></div><div class="" id="bloop_sign_1377868603913415936" style="font-family: helvetica; ">where foo is some function, which uses print statement in its body. Since we want to switch from print statements to print function we replace <font face="Courier New">print "Running foo ..." </font><font face="Helvetica">with a </font><font face="Courier New">print() </font><font face="Helvetica">call and add from </font><font face="Courier New">__future__ import ...</font><font face="Helvetica"> to the beginning of the module. </font></div><div class="" id="bloop_sign_1377868603913415936" style="font-family: helvetica; "><font face="Helvetica"><br></font></div><div class="" id="bloop_sign_1377868603913415936" style="font-family: helvetica; "><font face="Helvetica">What happens if we try to run the doctests after we've switched to </font><font face="Courier New">print_function</font><font face="Helvetica">?</font><br><div class="" id="bloop_sign_1377868603913415936"><br></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> $ python /tmp/foo.py</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> **********************************************************************</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> File "/tmp/foo.py", line 7, in __main__.foo</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> Failed example:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> print "foo"</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> Exception raised:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> Traceback (most recent call last):</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> File ".../doctest.py", line 1254, in __run</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> compileflags, 1) in test.globs</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> File "<doctest __main__.foo[0]>", line 1</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> print "foo"</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> ^</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> SyntaxError: invalid syntax</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> **********************************************************************</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> 1 items had failures:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> 1 of 1 in __main__.foo</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New"> ***Test Failed*** 1 failures.</font></div><span style="font-family: helvetica, arial; "></span></div><div style="font-family: helvetica; "><br></div><span style="font-family: helvetica; ">So, enabling </span><font face="Courier New">print_function</font><span style="font-family: helvetica; "> makes doctests using print statement fail with a SyntaxError, as shown by the example above. Thus, if we want to get rid of print statement in the code we have no other choice but to do the same it in the doctests</span><span style="font-family: helvetica; ">.</span><div style="font-family: helvetica; "><br><div>Sergei </div></div></div> <div class="" id="bloop_sign_1377869232729144064"><br><br><span style="font-family:helvetica,arial;font-size:13px"></span><span></span></div> <br><p style="color:#A0A0A8;">On August 30, 2013 at 5:14:14 PM, Peter Cock (p.j.a.cock@googlemail.com) wrote:</p> <blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;"><span><div>On Fri, Aug 30, 2013 at 1:58 PM, Sergei Lebedev <superbobry@gmail.com> wrote:
<br>>> (8) Excluding doctests and the Tutorial, use print function
<br>>> rather than print statement. e.g. replace this:
<br>>
<br>> Unfortunately we cannot exclude doctests, because 'from __future__' import
<br>> is module wide, thus the 'doctest.testmod()' will raise a SyntaxError on
<br>> docstrings with print statement.
<br>>
<br>> Sergei
<br>
<br>Could you clarify this? Does this cause a problem via:
<br>
<br>[Tests]$ python run_tests.py doctest
<br>
<br>If you have a small example, copy & paste the "git diff" output here.
<br>
<br>Peter
<br></div></span></blockquote></body></html>