Movatterモバイル変換


[0]ホーム

URL:


Changing global variables in tkinter/pmw callback

Jonathan Claggettjcc.ugm at ix.netcom.com
Fri Apr 6 13:33:36 EDT 2001


>(Or, you could use a 'grab-bag instance object' -- it>does not have to be a module-object; see for example>http://www.activestate.com/ASPN/Python/Cookbook/Recipe/52308).How about improving the Bunch class to allow subscript access to itsattributes? This makes an instance of Bunch reminiscent of a Javascriptinstance.>>> class Bunch:... def __init__(self, **kwds):...     self.__dict__.update(kwds)... def __setitem__(self, key, value):...     self.__dict__[key] = value... def __getitem__(self, key):...     return self.__dict__[key]...>>> ex = Bunch(salary=10000, rank=5)>>> ex.rank5>>> ex['salary']10000Or is this asking for trouble that I, an affirmed Python newbie, would notbe aware of? That's the trouble with languages, in addition to the syntaxrules there are always the undocumented 'good practice' rules :-)


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp