Version Number Comparison Function

Dan Sommers me at privacy.net
Fri Mar 25 11:31:10 EST 2005


On 25 Mar 2005 07:34:38 -0800,
"Keith" <vetter at lincom-asg.com> wrote:

> Is there a function for comparing version numbers?
> E.g.

> 0.1.0 < 0.1.2
> 1.876b < 1.876c
> 3.2.2 < 3.4

How about a simple string comparison?

Python 2.3.3 (#1, Mar  9 2004, 14:21:31) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> '0.1.0' < '0.1.2'
True
>>> '1.876b' < '1.876c'
True
>>> '3.2.2' < '3.4'
True
>>> 

Beyond that, there seems to be sufficient variation between version
number schemes, and something "interesting" often happens immediately
before the final version (e.g. "1.0rc4" becomes "1.0"), that you may
have to know something more about where you particular version numbers
come from.

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
μ₀ × ε₀ × c² = 1



More information about the Python-list mailing list