当我尝试创建类My_class的实例时,如果var1
不是"specific value"
班级定义:
class My_class:
def __init__(self,var1):
if var1 != "specific value":
raise ValueError("api_type not equal to faq")
用法:
import the_file
mc = My_class(var1= "something wrong")
在Python shell中它确实如此,但是使用IPython shell它甚至不会评估if。 有人能解释我为什么吗?