On 11/09/2014, at 5:25 PM, Ken McDonell wrote:
Hi Ken,
> The problem here is the version of Python ... it is 2.4.3 on CentOS 5.10.
> For Python 2.5 or earlier, "as" is not allowed and "," must be used.
FWIW, Python 2.4 was first released in November 2004, and was replaced by
Python 2.5 in September 2006. Red Hat continued to ship 2.4 with RHEL5 (GA
march 2007), before upgrading to Python 2.6 in RHEL6.
It's my impression that versions older than 2.6 are now largely ignored within
the Python community, with most people focusing on 2.7 and 3.x.
Of course, RHEL5 is a LTS distribution, and it's going to continue to support
Python-2.4 until March 2020, so this is probably a problem worth solving.
> So I need Python-expert guidance here ... in PCPland should we
>
> (a) disable all the Python bits for Python 2.5 or earlier?
I don't know enough about PCP to suggest that.
> (b) use the old-style "," everywhere (which apparently works in later
> versions)? or
The old-style "," will work in Python 2.x, up to 2.7 (the latest, and final
2.x). It will *not* work with Python 3.x.
The new-style "as" will work in Python 2.6, 2.7 and 3.x. It will not work in
Python 2.5 and earlier.
> (c) is there some clever Python trick I'm missing?
Maybe. See below (but it's pretty awful).
> This construct is _everywhere_ in the Python code (installed PCP bits and QA
> bits), so answer carefully.
I imagine that the current use of "as" is written either because the author was
unaware of the desire to support Python 2.5 and earlier, or because s/he felt
that support for Python 3.x with the same codebase was more important.
I know of one work-around in the Python code, although it's not pretty:
except ExceptionClass:
junk, err, junk = sys.exc_info()
# Use 'err' variable ...
is the same as
except ExceptionClass as err:
# Use 'err' variable ...
and will work across 2.x and 3.x.
The only other alternative I can think of is a post-install sed script
(hand-wave, hand-wave) that would convert the "as" syntax to "," syntax if the
system Python is 2.5 or earlier. I've done similar spec file hackage in the
past to mess about with the pyc/pyo byte-code generation, and I'm mostly
confident that it would work.
I'm not sure which of these is worse. For the sake of code-cleanliness and
future-compatibility I lean towards the post-install sed approach, even though
I think it's significantly uglier.
And at that point, I'll leave it to the PCP/Python regulars ...
d
signature.asc
Description: Message signed with OpenPGP using GPGMail
|