Steven Bethard <[EMAIL PROTECTED]> wrote:
I promised I'd put together a PEP for a 'generic object' data type for Python 2.5 that allows one to replace __getitem__ style access with dotted-attribute style access (without declaring another class). Any comments would be appreciated!
My experience from using this is that whenever I used Hash(), I found that later on in the refinement of the conversion it became its own class.
This has also generally been my experience, though I'm not sure it's as true for the XML DOM to Bunch translation. Did you use Hash() in the same way for hierarchical data?
So my take on the matter is that this encourages perl style programming (just ram it in a hash, and write lots of functions acting on it) rather than creating a specific class for the job which is dead easy in python anyway and to which you can attach methods etc.
You'll note that the (pre-)PEP explicitly notes that this object is intended only for use when no methods are associated with the attributes:
"When no methods are to be associated with the attribute-value mappings, declaring a new class can be overkill."
I do understand your point though -- people might not use Bunch in the way it's intended. Of course, those same people can already do the same thing with a dict instead (e.g. write a bunch of functions to handle a certain type of dict). If someone wants to write Perl in Python, there's not much we can really do to stop them...
Steve -- http://mail.python.org/mailman/listinfo/python-list