tools.py

changeset 36
cb4124e3e75b
parent 35
3b7a38af5c42
equal deleted inserted replaced
35:3b7a38af5c42 36:cb4124e3e75b
1 #
2 """
3 Helper functions and classes
4 """
5 import re
6
7 def str_num_cmp(s1,s2):
8 """
9 string comparator function that will put 'toto_10' after 'toto_2'
10 Also works for strings like 'toto_1_et_23er25'.
11 """
12 r = re.compile(r'((?<=\d)\D+|(?<=\D)\d+)')
13 r1= r.split(s1)
14 r2= r.split(s2)
15 r1=[not x.isdigit() and x or int(x) for x in r1 if x!='']
16 r2=[not x.isdigit() and x or int(x) for x in r2 if x!='']
17 return cmp(r1,r2)
18
19
1 class AbstractRegister(object): 20 class AbstractRegister(object):
2 _instance = None 21 _instance = None
3 _registered_type = None 22 _registered_type = None
4 def __new__(cls): 23 def __new__(cls):
5 # implements a singleton 24 # implements a singleton

mercurial