I thought I understood how import worked...

Roy Smith roy at panix.com
Tue Aug 7 11:32:50 EDT 2012


On Tuesday, August 7, 2012 9:55:16 AM UTC-4, Ben Finney wrote:

>  The tutorial is misleading on this. It it says plainly:
> 
>     A module can contain executable statements as well as function
>     definitions. […] They are executed only the *first* time the module
>     is imported somewhere.
> 
>     <URL:http://docs.python.org/tutorial/modules.html>

That's more than misleading.  It's plain wrong.  The example I gave demonstrates the "print __file__" statement getting executed twice.

The footnote to that is wrong too:

> [1]	In fact function definitions are also ‘statements’ that are ‘executed’; the execution of a
> module-level function enters the function name in the module’s global symbol table.

I think what it's supposed to say is "... the execution of a module-level def statement ..."

> Care to file a documentation bug <URL:http://bugs.python.org/>
> describing this?

Sure, once I understand how it's really supposed to work :-)




More information about the Python-list mailing list