Today, when I was learning a python custom function, I encountered a problem: I use the notepad++ Editor custom function, in the interactive environment using the From FileName Import function name Imports, has been an error, check several times, has been reported this error:
The code is as follows:
#-*-coding:utf-8-*-#Custom Function def function name (parameter 1, parameter 2 ...) : Then write the function body in the indent body, return the value with return#custom Seek absolute value function#def my_abs (x): #If the argument type is not int or float, the type error exception is thrown#if not isinstance (x, (Int,float)):#raise TypeError (' bad operand type ')#if x > 0:#return x#Else:#Return-x#Print (My_abs ( -2))ImportMathdefquadratic (a,b,c):if( notIsinstance (A, (int,float)))or( notIsinstance (b, (int,float)))or( notIsinstance (c, (Int,float))):RaiseTypeError ("Bad operand type") x= (b*b)/(4*a*a)-c/a Y= Math.sqrt (x)-b/(a)returnY
Finally found that the import of the time did not generate the compilation file, the previous compilation files are deleted and then re-import it.
Custom Function error in import file in Python interactive environment