Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If you import yourself in Python, why don't you get an infinite loop?

This question is a response to the following SO post:

How do I pickle an object?

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?

like image 569
froadie Avatar asked Aug 24 '10 16:08

froadie


1 Answers

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

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

like image 139
carl Avatar answered Nov 14 '22 21:11

carl