<div class="gmail_quote">On Fri, Jul 31, 2009 at 23:17, Alejandro Santos <span dir="ltr">&lt;<a href="mailto:alejolp@alejolp.com">alejolp@alejolp.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi,<br>
<br>
I&#39;d like to receive some feedback on the best way to import the email<br>
package to keep compatibility for Python 2.4, 2.5, 2.6 and Py3k.<br><br>
Option 1: Use a try:/except ImportError: block, and use a Py2.4 alias:<br>
<br>
# See patchbomb.py<br>
try: # Py2.5+, Py3k<br>
    import email.mime.multipart as MIMEMultipart<br>
    import email.mime.base as MIMEBase<br>
    import email.utils as Utils<br>
    import email.encoders as Encoders<br>
    import email.generator as Generator<br>
except ImportError: # Py2.4<br>
    import email.MIMEMultipart as MIMEMultipart<br>
    import email.MIMEBase as MIMEBase<br>
    import email.Utils as Utils<br>
    import email.Encoders as Encoders<br>
    import email.Generator as Generator<br>
<br>
This alternative goes against coding style (Uppercase, CamelCase), but<br>
is the least intrusive to the actual codebase.<br>
<br>
Option 2: Similar as before, using a lowercase convention and the<br>
&#39;email&#39; prefix to reduce at some degree name colissions:<br>
<br>
try: # Py2.5+, Py3k<br>
    import email.mime.multipart as emailmimemultipart<br>
    import email.utils as emailutils # Don&#39;t confuse with mercurial.util<br>
except ImportError: # Py2.4<br>
    import email.MIMEMultipart as emailmimemultipart<br>
    import email.Utils as emailutils<br>
<br>
</blockquote><div> </div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">I realize this requires a bigger change to the extension than Option 1, but I think it is better since it will be less confusing when people unfamiliar with the code look at it, since it follows current and future naming conventions, and uses the current and future names for the modules, which improves understandability.</span></div>

</div>