K
Keith
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
Keith
E.g.
0.1.0 < 0.1.2
1.876b < 1.876c
3.2.2 < 3.4
Keith
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
Keith
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
Keith said: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
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
[LooseVersion ('0.1.0'), LooseVersion ('0.1.2'), LooseVersionIs there a function for comparing version numbers?
E.g.
0.1.0 < 0.1.2
1.876b < 1.876c
3.2.2 < 3.4
FWIW,
Fredrik said:
Keith said:distutils is one of the places I looked:
http://www.python.org/doc/2.3.5/lib/module-distutils.html
But I didn't see the functions documented. I am new to Python so I
didn't know where else to look.
Using distutils seems like it would be the most generic and supported
way to compare version numbers.
the following works for many common cases:
import re
def cmpver(a, b):
def fixup(i):
try:
return int(i)
except ValueError:
return i
a = map(fixup, re.findall("\d+|\w+", a))
b = map(fixup, re.findall("\d+|\w+", b))
return cmp(a, b) # -1 if a<b, 0 if a=b, 1 if a>b
the following works for many common cases:
import re
def cmpver(a, b):
def fixup(i):
try:
return int(i)
except ValueError:
return i
a = map(fixup, re.findall("\d+|\w+", a))
b = map(fixup, re.findall("\d+|\w+", b))
return cmp(a, b) # -1 if a<b, 0 if a=b, 1 if a>b
[OT] Visually, I like the nested def fixup, and I realize
that for cmpver execution overhead is not likely to be an issue,
but in general, what do you think of not being able
to write it that way if MAKE_FUNCTION overhead is unacceptable?
What if we had something like
@sticky('fixup') # evaluate binding only first time
def cmpver(a , b):
def fixup ... ?
http://groups-beta.google.com/group...4&mode=thread&noheader=1#doc_7599103bb19c7332Christos said:One of the previous related threads is this (long URL):
The real problem with Python is ... Python is
going the C++ way: piling feature upon feature, adding bells
and whistles while ignoring or damaging its core design.
Do you have specific recommendations that might benefit python 3000?http://groups-beta.google.com/group...4&mode=thread&noheader=1#doc_7599103bb19c7332
Another previous message on this issue:
http://groups-beta.google.com/group/comp.lang.lisp/msg/1615d8b83cca5b20
Python's syntax surely is not clean enough for concise metaprogramming.
At any rate, I'd agree with Fernando's assessment:
If the core design were better, many "new features" in Python could
have been rendered unnecessary.
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.