<div class="gmail_quote">On 17 February 2012 04:55, Antoine Pitrou <span dir="ltr">&lt;<a href="mailto:solipsis@pitrou.net">solipsis@pitrou.net</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">But then you&#39;re going from a cumbersome situation (where you have to</div>
import cElementTree and then fallback on regular ElementTree) to an<br>
even more cumbersome one (where you have to first check the Python<br>
version, then conditionally import cElementTree, then fallback on<br>
regular ElementTree).</blockquote><div><br></div><div>Well, you can reverse the import so you&#39;re not relying on version numbers:</div><div><br></div><div>import xml.etree.ElementTree as ElementTree</div><div><br></div>
<div>try:</div><div> import xml.etree.cElementTree as ElementTree</div><div>except ImportError:</div><div> pass</div><div><br></div><div>There is a slight cost compared to previously (always importing the python version) and you&#39;ll still be using cElementTree directly until it&#39;s removed, but if/when it is removed you won&#39;t notice it.</div>
<div><br></div><div>Tim Delaney</div></div>

AltStyle によって変換されたページ (->オリジナル) /