question about scope

John Salerno johnjsal at NOSPAMgmail.com
Sun Oct 1 13:35:52 EDT 2006


Steve Holden wrote:
> John Salerno wrote:
>> James Stroud wrote:
>>
>>
>>> This is because that list is an attribute of the class. Instances have a 
>>> reference of this class attribute, but it can be replaced by an 
>>> attribute of the instance with self (self is a reference to the instance 
>>> and not the class. This example might help:
>>
>> Ah, I see! So within my create_menubar() method, would it better to 
>> refer to menu_items as DataAccessFrame.menu_items? Or does it not matter 
>> in this case, since I'm not reassigning it per instance?
> 
> I'd prefer to use a self-relative reference, though either works in your 
> example. That way the code will work for subclasses with different menus 
> too. Perhaps not relevant in your case, but a general point.
> 
> regards
>   Steve

Thanks!



More information about the Python-list mailing list