<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,&nbsp;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">&nbsp; &nbsp; # +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">&nbsp; &nbsp; def foo():</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; """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">&nbsp; &nbsp; &nbsp; &nbsp; &gt;&gt;&gt; print "foo"</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; foo</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; """</font></div><div id="bloop_customfont" style="margin: 0px; "><span style="font-family: 'Courier New'; ">&nbsp; &nbsp; &nbsp; &nbsp; print "Running foo ...</span><span style="font-family: 'Courier New'; ">"</span></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; # +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">&nbsp; &nbsp; if __name__ == "__main__":</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; import doctest</font></div><div id="bloop_customfont" style="margin: 0px; "><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; 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&nbsp;<font face="Courier New">print "Running foo ..."&nbsp;</font><font face="Helvetica">with a&nbsp;</font><font face="Courier New">print()&nbsp;</font><font face="Helvetica">call and add from&nbsp;</font><font face="Courier New">__future__ import ...</font><font face="Helvetica">&nbsp;to the&nbsp;beginning&nbsp;of the module.&nbsp;</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&nbsp;</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">&nbsp; &nbsp; $ python /tmp/foo.py</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; **********************************************************************</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; File "/tmp/foo.py", line 7, in __main__.foo</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; Failed example:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; print "foo"</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; Exception raised:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; Traceback (most recent call last):</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File ".../doctest.py", line 1254, in __run</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; compileflags, 1) in test.globs</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File "&lt;doctest __main__.foo[0]&gt;", line 1</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print "foo"</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp; SyntaxError: invalid syntax</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; **********************************************************************</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; 1 items had failures:</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; &nbsp; &nbsp;1 of &nbsp; 1 in __main__.foo</font></div><div class="" id="bloop_sign_1377868603913415936"><font face="Courier New">&nbsp; &nbsp; ***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&nbsp;</span><font face="Courier New">print_function</font><span style="font-family: helvetica; ">&nbsp;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&nbsp;</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 &lt;superbobry@gmail.com&gt; wrote:
<br>&gt;&gt; (8) Excluding doctests and the Tutorial, use print function
<br>&gt;&gt; rather than print statement. e.g. replace this:
<br>&gt;
<br>&gt; Unfortunately we cannot exclude doctests, because 'from __future__' import
<br>&gt; is module wide, thus the 'doctest.testmod()' will raise a SyntaxError on
<br>&gt; docstrings with print statement.
<br>&gt;
<br>&gt; 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 &amp; paste the "git diff" output here.
<br>
<br>Peter
<br></div></span></blockquote></body></html>