on-internet
← Community

Function definition in Python takes a lot of time

Stack Overflow ·

Why is python trying to calculate the value of p during definition? It takes ages to define this function. def f(): raise Exception('Some error') p = 2322111239**42322222334923492304923 print 'Defined!' Also if the value of p is being calculated during definition, why is it possible to define this function without errors? def f(): return 4 p = 11/0 This one obviously works fine because constants are not involved: def f(): raise Exception('Some error') x=42322222334923492304923 p = 2322111239**x print 'Defined!'

Comments

Sign in or sign up to comment and upvote.

No comments yet.