I'm not sure what the comprehension for data
is trying to achieve, your basically going a long way around stepping through each value in tagVals, which you already know will be in groups of the length of headers.
Either way, the dictionary script:
headers = ['Number', 'Type', 'Name']
paths = getUDTtagPathsList('Grain_Equipment')
data = [[equip.value[eqNumber],equip.value[eqType],equip.value[eqName]] for equip in equipment]
return system.dataset.toDataSet(headers,data)
For the second one, I would throw this function into your utilities library because it is super handy for things just like this:
def chunker(seq,size):
return (seq[pos:pos + size] for pos in xrange(0,len(seq),size))
Then your second script can be this:
EDIT: replaced zip with product, as @pascal.fragnoud correctly pointed out, zip is not what we want in this instance.
from itertools import product
headers = ['Number', 'Type', 'Name']
paths = ['{}/{}'.format(path,suffix) for path,suffix in product(getUDTtagPathsList('Grain_Equipment'),headers)]
data = [[qv.value for qv in chunk] for chunk in chunker(system.tag.readBlocking(paths),len(headers))]
return system.dataset.toDataSet(headers,data)
You may feel that is less readable (particularly for the un-initiated), and that's fair. To me the difference is negligible, but as the UDT list increases the second will be more performant. The only way to be certain is to measure the performance on your system. Either one is a perfectly acceptable way to do what you're doing.