Quote:
Originally Posted by sweth
Hmm. Is the answer maybe template functions? I was able to define a sum() function that appears to work (once I realized that args are passed in as unicode and needed to be converted before being added), but am a python newbie so the extraction of the Ns from an arbitrary number of tags is still befuddling me...
|
Given your use case, a template function is definitely the way to go.
Are you asking how to extract the N values in a template function? If the following is true:
- The source of the values is always the field "tags".
- The pattern is always 'recommended\..*\.[\d.]+'
Then something like the following should work for you:
Code:
def evaluate(self, formatter, kwargs, mi, locals):
import re
tags = mi.get('tags')
v = 0
if tags:
for t in tags:
m = re.match('recommended\..*\.([\d.]+)', t)
if m:
v = v + int(m.group(1))
return v