I have the following code:
from sys import stdin
import re
def main():
def hidden1_test(): return hidden1('test')
def hidden2_test(): return hidden2('test')
tasks = [dna, sorted, hidden1_test, hidden2_test, equation, parentheses, sorted3]
print('Skriv in teststrängar:')
while True:
line = stdin.readline().rstrip('\r\n')
if line == '': break
for task in tasks:
result = '' if re.search(task(), line) else 'INTE '
print('%s(): "%s" matchar %suttrycket "%s"' % (task.__name__, line, result, task()))
if __name__ == '__main__': main()
Functions in the list tasks are defined above but they are not important for my question. I understand the entire run of the function main up until the last two rows:
result = '' if re.search(task(), line) else 'INTE '
print('%s(): "%s" matchar %suttrycket "%s"' % (task.__name__, line, result, task()))
I don't understand what task.__name__
means. Name must be __name__ == '__main__'
so i suppose my question becomes what does task.'__main__'
mean (correct me if i am wrong)? I interpret the first row of the two above as:
result = ''
if re.search(task(), line):
else:
'INTE '
I know this can't be right since there is nothing under the if statement, but I don't know how to test the code to get an understanding of what it means. I am just trying to get a better understanding so an explanation for someone who is not a very advanced programmer would be nice
Thanks in advance!