如果您使用Python导入自己,为什么不进行无限循环? [英] If you import yourself in Python, why don't you get an infinite loop?

查看:98
本文介绍了如果您使用Python导入自己,为什么不进行无限循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题是对以下SO帖子的回复:

This question is a response to the following SO post:

我如何挑选一个物体?

在那个线程中,OP不小心导入了他自己的模块在同一模块的顶部。为什么这不会导致无限循环?

In that thread, the OP accidentally imports his own module at the top of the same module. Why doesn't this cause an infinite loop?

推荐答案

模块只导入一次。 Python意识到它已经被导入了,所以不再这样做了。

Modules are imported only once. Python realizes it already has been imported, so does not do it again.

参见: http://docs.python.org/tutorial/modules.html#more-on-modules

这篇关于如果您使用Python导入自己,为什么不进行无限循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆