newb: Python Module and Class Scope

Duncan Booth duncan.booth at invalid.invalid
Fri May 11 07:19:48 EDT 2007


Dave Baum <Dave.Baum at motorola.com> wrote:

> In article <1178805769.658287.178240 at q75g2000hsh.googlegroups.com>,
>  johnny <rampeters at gmail.com> wrote:
> 
>> scope of "def main()" interms of class A?
>> 
>> myModule:
>> 
>> class A:
>>    main()
>> 
>> def main():
>> 
> 
> Yes, class A can access main.  The name "main" will be defined at the 
> top level of the module, and is considered a global for that module.

No, the name "main" will be defined when the execution of the 'def main()' 
statement is complete. It is not defined until that point.

In the example given the class statement is executed before the def 
statement is executed so at that point main is still undefined.



More information about the Python-list mailing list