PyScore

01: # -*- python -*-
02: ######## utils.py ######## python package PyScore.utility module utils ########
03: 
04: # PyScore
05: # a race scoring programme
06: # written by Matt Draisey
07: # 2004 April 6
08: 
09: reloadable=True
10: reloadables=[]
11: 
12: ######## utils.py ######## python package PyScore.utility module utils ########
13: 
14: # common generic helper functions
15: 
16: def whittle(*t):
17:     while t and not t[-1]:
18:         t=t[:-1]
19:     return t
20: 
21: def whittle_down_to(minimum=0,*t):
22:     l=len(t)
23:     while l>minimum and t and not t[-1]:
24:         t=t[:-1]
25:         l-=1
26:     return t
27: 
28: def pad(n,nil="",*t):
29:     if n>len(t):
30:         return t+(nil,)*(n-len(t))
31:     else:
32:         return t[:n]
33: 
34: def safe_int(t):
35:     try:
36:         return int(t)
37:     except ValueError:
38:         return 0
39: 
40: ######## utils.py ######## python package PyScore.utility module utils ########