Changing global variables in tkinter/pmw callback

Jonathan Claggett jcc.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 its
attributes? This makes an instance of Bunch reminiscent of a Javascript
instance.

>>> 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.rank
5
>>> ex['salary']
10000


Or is this asking for trouble that I, an affirmed Python newbie, would not
be aware of? That's the trouble with languages, in addition to the syntax
rules there are always the undocumented 'good practice' rules :-)





More information about the Python-list mailing list