Close. I would recommend that you keep the two functions in a Script Library.
Really you should define another function in a script library that holds all of the actual code in a script library., but you don't have to.
If you choose to just define them in this script then, all of the imports should be on the first line, I just did it in each function for clarity (and so the functions by themselves can be used without modification).
So it should look like this:
def runAction(self, event):
from itertools import repeat,izip_longest as zipl
from itertools.chain import from_iterable as chainIt
def chunks(it,size):
return zipl(*[iter(it)] * size)
def rangeGroup(it,start,n):
for i,j in zip(chainIt(repeat(k,len(it)) for k in xrange(start,n)),chainIt(repeat(it,n))):
yield (i,j)
quad = ['A','B','C','D']
path = '[default]Twisters/TW{}/Operator Assignments/Quad_{} {}'
tags = ['J Shift Operator Name','J Shift Operator BadgeNum']
paths = [path.format(i,n,tag) for i,n in rangeGroup(quad,0,66) for tag in tags]
tagValues = [qv.value for qv in system.tag.readBlocking(paths)]
#I incremented the end value here rather than in the loop.
tw_ranges = [(1,13),(13,25),(25,41),(41,57),(57,66)]
for cc_index,(tw_start,tw_end) in enumerate(tw_ranges):
for tw_num,quad in rangeGroup(quad,tw_start,tw_end):
cont = 'CoordinateContainer_{}'.format(cc_index)
tw = 'TW{}'.format(tw_num)
nameQuad = 'Quad_{}_OpName'.format(quad)
numQuad = 'Quad_{}_OpNum'.format(quad)
for opName,opNum in chunks(tagValues,2):
self.parent.getChild(cont).getChild(tw).props.params[nameQuad] = opName
self.parent.getChile(cont).getChild(tw).props.params[numQuad] = opNum
Honestly though, it should really look like this:
def runAction(self,event):
shared.someScriptLibrary.someScriptFile.populateComponents(self)