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


Groups > comp.lang.python > #46704

Re: Python 2-3 compatibility

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <drsalists@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'package,': 0.03; 'subject:Python': 0.06; 'duplicate': 0.07; 'important,': 0.07; 'result,': 0.07; '2to3': 0.09; 'exception,': 0.09; 'subject:skip:c 10': 0.09; 'try:': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'project,': 0.12; 'wrote': 0.14; '(next': 0.16; 'cc:name:python list': 0.16; 'err:': 0.16; 'quantum': 0.16; 'syntax,': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'module': 0.19; 'everyone,': 0.19; 'possible,': 0.19; '8bit%:5': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; '2.x': 0.24; 'ph.d.': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'script': 0.25; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'appreciated.': 0.29; 'am,': 0.29; 'unix': 0.29; 'field,': 0.30; 'primarily': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'getting': 0.31; '3.x': 0.31; 'exceptions': 0.31; 'compatible': 0.32; 'thanks!': 0.32; 'linux': 0.33; 'url:python': 0.33; 'actively': 0.33; 'candidate': 0.34; 'role': 0.34; "i'd": 0.34; 'could': 0.34; 'received:209.85': 0.35; 'except': 0.35; 'possible.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'ubuntu': 0.36; 'url:listinfo': 0.36; 'url:org': 0.36; 'should': 0.36; 'project': 0.37; 'received:209': 0.37; 'jason': 0.38; 'rather': 0.38; 'heard': 0.39; 'supporting': 0.39; 'university': 0.39; '8bit%:6': 0.40; 'url:mail': 0.40; 'catch': 0.60; 'url:%20': 0.61; 'course': 0.61; 'soon': 0.63; 'become': 0.64; 'more': 0.64; '(that': 0.65; 'to:addr:gmail.com': 0.65; 'due': 0.66; 'news': 0.67; 'url:pdf': 0.68; 'url:%1': 0.72; 'florida': 0.78; 'introduce': 0.78; 'ships': 0.84; '\xa0of': 0.84; 'migrating': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=ubFxuPhgdisJZAzH+REjWcUSkAtj7g/KdQCcHnAJzV4=; b=lpvRzzeLi3CdDmbEPpDKjuLRFVg3zCGroK+kjiMP0jA2TAod+MMW17UoEki/uI0QA7 m/DMNUc4SlUIel0K+xsJ4krE8WocTMiL/YSDLuFZVkJOHQvUxTcIscWGqPPkwrprCsGt zua8O26vjTthh6F9EhYaXAzH3DMZXXZN/0prsC7XS4Mq+Bwi4gZKukMe8TvZ06LMdhdw KL5TyC8O5xHHYxci6Y0g5teHxZrpyJFqxrnp4NZ6gC+dv3et+gZSK8TVzP95H/pL7RN1 odk6NE2wKVDLIGIgY2GzeHXWktwmV2cWQyhuYOSYlE5ZQis/sAwKD9Hw+yK2n9WAEJNb d8+g==
MIME-Version 1.0
X-Received by 10.49.39.68 with SMTP id n4mr17700087qek.44.1370191294704; Sun, 02 Jun 2013 09:41:34 -0700 (PDT)
In-Reply-To <CAEk9e3rUcn6AooKLOtJO=DbD9oM4WHUNaFxYfn2xf45V_vfiew@mail.gmail.com>
References <CAEk9e3rUcn6AooKLOtJO=DbD9oM4WHUNaFxYfn2xf45V_vfiew@mail.gmail.com>
Date Sun, 2 Jun 2013 09:41:34 -0700
Subject Re: Python 2-3 compatibility
From Dan Stromberg <drsalists@gmail.com>
To Jason Swails <jason.swails@gmail.com>
Content-Type multipart/alternative; boundary=047d7bd769346562fd04de2e8501
Cc python list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2548.1370191302.3114.python-list@python.org> (permalink)
Lines 138
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370191302 news.xs4all.nl 15958 [2001:888:2000:d::a6]:53358
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:46704

Show key headers only | View raw


[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
>
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web