class TimeUtil():
def calculate_seconds(self, input):
if any(x in input.lower() for x in ['weeks', 'week','wks','wk']):
return (int(find_digit(self, input))*604800)
elif any(x in input.lower() for x in ['days', 'day']):
return (int(find_digit(self, input))*86400)
elif any(x in input.lower() for x in ['hours', 'hour','hr','hrs']):
return (int(find_digit(self, input))*3600)
elif any(x in input.lower() for x in ['minutes', 'minute','min','mins']):
return (int(find_digit(self, input))*60)
elif any(x in input.lower() for x in ['seconds', 'second','sec','secs']):
return (int(find_digit(self, input))*60)
else:
return -1
def find_digit(self, text):
return ''.join(input for input in text if input.isdigit())
By calling find_digit method in another method calculate_seconds I could see the error as "find_digit is not defined Pylance (reportUndefinedVaribale)"
>Solution :
I noticed that the way your calling find_digit() is like that:
find_digit(self, input)
You probably meant to write it like that:
TimeUtil.find_digit(self, input)
but you should write it like that because it’s more readable:
self.find_digit(input)