Python 2-3 compatibility

J

Jason Swails

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top