<div class="gmail_quote"><div class="gmail_quote"><div class="im">On 22 July 2012 14:08, R. David Murray <span dir="ltr">&lt;<a href="mailto:rdmurray@bitdance.com" target="_blank">rdmurray@bitdance.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Sun, 22 Jul 2012 11:21:38 +0300, anatoly techtonik &lt;<a href="mailto:techtonik@gmail.com" target="_blank">techtonik@gmail.com</a>&gt; wrote:<br>
&gt; <a href="http://docs.python.org/py3k/howto/pyporting.html#during-installation" target="_blank">http://docs.python.org/py3k/howto/pyporting.html#during-installation</a><br>
&gt;<br>
&gt; What&#39;s the point in making implicit Python 3 check here:<br>
&gt; try:  # Python 3<br>
&gt;   from distutils.command.build_py import build_py_2to3 as build_py<br>
&gt; except ImportError:  # Python 2<br>
&gt;   from distutils.command.build_py import build_py<br>
&gt;<br>
&gt; instead of explicit check like:<br>
&gt; import sys<br>
&gt; if sys.version_info[0] &gt;= 3:<br>
&gt;     from distutils.command.build_py import build_py_2to3 as build_py<br>
<br>
</div>It&#39;s called testing for the thing that actually matters, rather than<br>
testing a constant with a much broader meaning.  Yes, in this case the<br>
results are the same, but IMO it is better programming practice to test<br>
the thing that actually matters when you can.</blockquote><div><br></div></div><div>I recently changed a setup.py from try/ImportError to an explicit sys.version_info check. I&#39;m not totally sure how to reproduce this but I had a problem where I was installing into a 2.x virtualenv and it was running 2to3 during install and subsequently failing to import the 3.x code (the problem didn&#39;t occur when using the same python that generated the virtualenv).</div>

<div><br></div><div>I may be wrong but I imagined that sometimes build_py_2to3 is importable on 2.x, perhaps for cross-building or something. In any case &#39;testing the thing that matters&#39; means testing what version of Python you are about to install into not whether the python version supports running 2to3.</div>

<div><br></div><div>Cheers,</div><div>Oscar.</div></div>
</div><br>