Python reference problem -
I am experiencing a very strange problem (for me) in Python.
I have a square menu: (snippet)
class menu: "" fixed item "" menu_items = {} letters = map (chr, range (97 , 123)) Diff __int_ (self, menu_items): self.init_menu (menu_items) def init_menu (self, menu_items): i = 0 items in menu_items: self.menu_items [self.characters [i]] = item i + = 1
When I instantate the class, I am in a list of dictionaries, dictionaries are created with this function:
def menu_item (Description, verb = none): if action == none: verb = Lambda: Any returns {"description": description, "action": Action}
and then the lists are created like this:
t = [Menu_item ("abcd")] m3 = menu.Menu (t) = A = [menu_item ("test")] m2 = menu.Menu (a) b = [menu_item ("update", m2.getAction), menu_item ("Add"), menu_item ("Delete")] m = Menu. Menu (B)
When I run my program, I get the same menu items every time . I have run the program with PDB and as soon as another example of a class is seen, the menu_items of all previous classes are set in the latest list. It seems that the menu_items member is a static member.
What am I seeing here?
Take a look for more thorough discussion in between class attributes and frequency attributes. menu_itum
dict is a class attribute that is all the menu Examples, and instead you should be OK:
Category menu: "" defined item "=" character = map (chr, range (97) , 123) shows a menu with the following: Def __init __ (self, menu_items): self.menu_items = {} self.init_menu (menu_items) [...]
Comments
Post a Comment