Hello All,
If "__call__" allows anobject() and "__getitem__" allows anobject[arange], why
not have "__brace__" (or some other, better name) for anobject{something}.
Such braces might be useful for cross-sectioning nested data structures:
anary = [[1,2,3],[4,5,6]]
anary{2} ==> [3,6]
or for a list of dictionaries:
alod = [{"bob":1,"ted":2,"carol":3},{"bob":4,"ted":5,"caro l":6}]
alod{"ted"} ==> [2,5]
or, heck, a dictionary of lists:
adol = {"bob":[1,2,3],"carol":[4,5,6],"alice":[7,8,9]}
adol{1} ==> {"bob":2, "carol":5, "alice":8}
Though I positively can not see what is wrong with this suggestion, I am sure
this will raise more than a few objections. Please bash my naivete publicly
on the list.
Some preemptive observations
1. on syntactic ambiguity (i.e. "braces already used")
[] ==> used for both list and getitem (both for dict AND list)
() ==> used for tuple, callable, grouping
2. on functional ambiguity (i.e. "function not implicit"):
Q. What exactly does it mean to call an instance of class MyClass?
A. Whatever the author of MyClass wanted it to mean.
etc.
Also, if this exists already, I apologize because I have not seen it in any
Python code before and I wouldn't know what to call it for googling.
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/