question about scope
Steve Holden
steve at holdenweb.com
Sun Oct 1 13:10:16 EDT 2006
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
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list