[docs] Cpython sys.version parser in platform.py bug and resolution?

Zerbe, Brandon ZerbeB at humgen.ucsf.edu
Tue Sep 3 22:33:58 CEST 2013

To whom this may concern;

I am contacting you in the hope that I may provide help to others by addressing a possible, very small bug (assuming I diagnosed and solved the issue correctly).  No need to contact me since I consider my solution as sufficient.

I ran into an exception today from a program running plaftorm.py using python version 2.7.5.  Here is the code in platform.py that produced the exception (line 1454)

match = _sys_version_parser.match(sys_version)
if match is None:
    raise ValueError(
        'failed to parse CPython sys.version: %s' %

This results from the following regular expression:

_sys_version_parser = re.compile(
    '\|[^|]*\|\s*' # version extra
    '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'

At least on my computer, CPython does not have "version extra".  So I simply removed the second part of the regular expression and put it into a new object:

_cpython_sys_version_parser = re.compile(
    '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'

I then called this object for cpython, and it appears to have worked (fingers crossed).


Brandon Zerbe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20130903/4d3f7279/attachment.html>

More information about the docs mailing list