Having troubles with this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Having troubles with this code

Having troubles at line 10. It's recognizing _enter_ as an Attribute Error from functools import reduce mul = lambda n1,n2: n1*n2 class cls: def _enter_(self): def f(n): return reduce(mul,range(2,n+1),1) return f def _exit_(self,*args): pass with cls() as a: print(a(5))

23rd May 2021, 7:48 PM
Felipe Osorio
Felipe Osorio - avatar
1 Answer
+ 1
rather, python notice that you probably write _enter_ instead of __enter__ (magic method takes two underscore before and after name)... same for _exit_ wich should maybe written __exit__ ^^
23rd May 2021, 8:32 PM
visph
visph - avatar