Code: Select all
def extract(self, fmtArray, pathArray, args):
if len(fmtArray) != len(pathArray):
return False
if len(fmtArray) == 0:
return True
fmt = fmtArray[0]
path = pathArray[0]
if fmt == path:
return self.extract(fmtArray[1:], pathArray[1:], args)
if fmt.startswith("%"):
fmt = fmt[1:]
t = 's'
if fmt[0] == '(':
if fmt[-1] == ')':
name = fmt[1:-1]
elif fmt[-2] == ')':
name = fmt[1:-2]
t = fmt[-1]
else:
raise Exception("Missing closing brace")
else:
name = fmt
if t == 's':
args[name] = path
elif t == 'b':
args[name] = types.str2bool(path)
elif t == 'd':
args[name] = types.toint(path)
elif t == 'x':
args[name] = int(path, 16)
elif t == 'f':
args[name] = float(path)
else:
raise Exception("Unknown format type : %s" % t)
return self.extract(fmtArray[1:], pathArray[1:], args)
return False
I couldn't understand what the above function does. Anyone has some insight and give example?
what's pathArray[1:] versus pathArray[1:-1]?