"static" variables in functions (was: Version Number Comparison Function)
Christos TZOTZIOY Georgiou
tzot at sil-tec.gr
Mon Mar 28 16:08:06 CEST 2005
On Fri, 25 Mar 2005 19:23:37 GMT, rumours say that bokr at oz.net (Bengt
Richter) might have written:
>On Fri, 25 Mar 2005 17:02:31 +0100, "Fredrik Lundh" <fredrik at pythonware.com> wrote:
>>> Is there a function for comparing version numbers?
>>> 0.1.0 < 0.1.2
>>> 1.876b < 1.876c
>>> 3.2.2 < 3.4
>>the following works for many common cases:
>>def cmpver(a, b):
>> def fixup(i):
>> 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 ... ?
One of the previous related threads is this (long URL):
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...
More information about the Python-list