首页 > python 中归替为什么会出错呢?

python 中归替为什么会出错呢?

class START:
    def main(self):
	    for num in xrange(1,10):
		    print num
	    self.main()
 
if __name__ == "__main__":
   START().main()

这段代码为什么执行起来会出现:
RuntimeError: maximum recursion depth exceeded while calling a Python object


Python限制递归的层数。

Python-2.6.8/Python/ceval.c

#define Py_DEFAULT_RECURSION_LIMIT 1000

START.main函数没有递归调用终止条件,是个无穷递归。

【热门文章】
【热门文章】