Popular Python recipes tagged "keys"http://code.activestate.com/recipes/langs/python/tags/keys/2013-09-29T14:13:04-07:00ActiveState Code RecipesPyQt4 pressed modifier keys names as method argument by a decorator (Python) 2013-09-29T14:13:04-07:00TNThttp://code.activestate.com/recipes/users/4187961/http://code.activestate.com/recipes/578675-pyqt4-pressed-modifier-keys-names-as-method-argume/ <p style="color: grey"> Python recipe 578675 by <a href="/recipes/users/4187961/">TNT</a> (<a href="/recipes/tags/keys/">keys</a>, <a href="/recipes/tags/modifier/">modifier</a>, <a href="/recipes/tags/pyqt/">pyqt</a>). Revision 2. </p> <p>This is a definition of a decorator function that checks which modifier keys are being pressed and adds a keyword argument to a method. This argument is a tuple of names (strings) of the modifier keys that have been pressed when the method was called (or triggered).</p> Dictionary Who's Keys Act Like Attributes As Well (Python) 2011-05-26T20:15:16-07:00Sunjay Varmahttp://code.activestate.com/recipes/users/4174115/http://code.activestate.com/recipes/577590-dictionary-whos-keys-act-like-attributes-as-well/ <p style="color: grey"> Python recipe 577590 by <a href="/recipes/users/4174115/">Sunjay Varma</a> (<a href="/recipes/tags/attribute/">attribute</a>, <a href="/recipes/tags/dict/">dict</a>, <a href="/recipes/tags/keys/">keys</a>). </p> <p>Think of this as a JavaScript object. In JavaScript, the objects can be referenced by indexing (e.g. d[name]) or by directly using the dot (.) operator (e.g. d.name).</p> <p>This is the same concept. </p> <p><strong>Note to Python 2.4 Users:</strong> You will need to change the "except KeyError as e:" line to "except KeyError, (e):".</p>