Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46704 > unrolled thread

Re: Python 2-3 compatibility

Started byDan Stromberg <drsalists@gmail.com>
First post2013-06-02 09:41 -0700
Last post2013-06-02 09:41 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Python 2-3 compatibility Dan Stromberg <drsalists@gmail.com> - 2013-06-02 09:41 -0700

#46704 — Re: Python 2-3 compatibility

FromDan Stromberg <drsalists@gmail.com>
Date2013-06-02 09:41 -0700
SubjectRe: Python 2-3 compatibility
Message-ID<mailman.2548.1370191302.3114.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

From
http://stromberg.dnsalias.org/~dstromberg/Intro-to-Python/Python%202%20and%203.pdf:

Try/Except: both 2.x and 3.x

try:
   print(1/0)
except ZeroDivisionError:
   extra = sys.exc_info()[1]
   print('oops')

HTH



On Sun, Jun 2, 2013 at 7:13 AM, Jason Swails <jason.swails@gmail.com> wrote:

> Hello Everyone,
>
> I have a Python script that I wrote to support a project that I work on
> (that runs primarily on Unix OSes).  Given its support role in this
> package, this script should not introduce any other dependencies.  As a
> result, I wrote the script in Python 2, since every Linux currently ships
> with 2.4--2.7 as its system Python (RHEL 5, still popular in my field,
> ships with 2.4).
>
> However, I've heard news that Ubuntu is migrating to Python 3 soon (next
> release??), and that's a platform we actively try to support due to its
> popularity.  I've tried writing the code to support both 2 and 3 as much as
> possible, but with priority put on supporting 2.4 over 3.
>
> Now that Python 3-compatibility is about to become more important, I'm
> looking for a way to catch and store exceptions in a compatible way.
>
> Because Python 2.4 and 2.5 don't support the
>
> except Exception as err:
>
> syntax, I've used
>
> except Exception, err:
>
> Is there any way of getting this effect in a way compatible with Py2.4 and
> 3.x?  Of course I could duplicate every module with 2to3 and do
> sys.version_info-conditional imports, but I'd rather avoid duplicating all
> of the code if possible.
>
> Any suggestions are appreciated.
>
> Thanks!
> Jason
>
> --
> Jason M. Swails
> Quantum Theory Project,
> University of Florida
> Ph.D. Candidate
> 352-392-4032
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web