I have the following functions in python:
def extractParam(word, varName, stringToReplace):
if word.startswith(stringToReplace):
varName=int (word.replace(stringToReplace, ''))
return varName
def getMParams(line):
l = r = b = t = 0
sline = line.strip().split()
for i in range(len(sline)):
l = extractParam(sline[i], l, "l=")
r = extractParam(sline[i], r, "r=")
b = extractParam(sline[i], b, "b=")
t = extractParam(sline[i], t, "t=")
return l, r, b, t
def getIterParams (line):
width = height = stride = x = y = 0
sline = line.strip().split()
for i in range(len(sline)):
width = extractParam(sline[i], width, "width=")
height = extractParam(sline[i], height,"height=")
stride = extractParam(sline[i], stride,"stride=")
x = extractParam(sline[i], x, "x=")
y = extractParam(sline[i], y, "y=")
return width, height , stride, x, y
the functions getMparams and getIterParams are quite the same, my question is if there's a way to create a function that will replace both of them, I was thinking about something like that:
def func (line, params)
//params is an array of parameters (i.e [l,r,b,t] or [width,height,stride,x,y])
//init all params
sline = line.strip().split()
for i in range(len(sline)):
//for everyParam:
param = extractParam(sline[i],param,"param=")
is it possible? or there's another way to do it?