"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:
>
>>"Keith" 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
>>
>>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 ... ?

One of the previous related threads is this (long URL):

http://groups-beta.google.com/group/comp.lang.python/messages/f7dea61a92f5e792,5ce65b041ee6e45a,dbf695317a6faa26,19284769722775d2,7599103bb19c7332,abc53bd83cf8f636,4e87b44745a69832,330c5eb638963459,e4c8d45fe5147867,5a184dac6131a61e?thread_id=84da7d3109e1ee14&mode=thread&noheader=1#doc_7599103bb19c7332
-- 
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 mailing list