|
|||||
|
|
#1 |
|
|
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 cl*** MyCl***? A. Whatever the author of MyCl*** 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/ |
|
|
#2 |
|
|
> why not have "__brace__" (or some other, better name) > for anobject{something}. Such braces might be useful for > cross-sectioning nested data structures: This seems like a pretty esoteric operation to devote a bit of syntax to. It doesn't seem like something people want to do very often. |
|
|
#3 |
|
|
> This seems like a pretty esoteric operation to devote a bit of syntax to. > It doesn't seem like something people want to do very often. Similar to __call__, I don't think that this syntax would be neccessarily devoted to any particular operation. I'm simply offering cross-sectioning as a potential and intuitive operation that would benefit from a shortcut. The main point is that using braces after a name is not defined right now and I think that they could be put to good use. James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ |
|
|
#4 |
|
|
In article <mailman.177.1115599072.29826.python-list@python.org>,
James Stroud <jstroud@mbi.ucla.edu> wrote: > On Sunday 08 May 2005 05:15 pm, Roy Smith wrote: > > This seems like a pretty esoteric operation to devote a bit of syntax to. > > It doesn't seem like something people want to do very often. > > Similar to __call__, I don't think that this syntax would be neccessarily > devoted to any particular operation. I'm simply offering cross-sectioning as > a potential and intuitive operation that would benefit from a shortcut. The > main point is that using braces after a name is not defined right now and I > think that they could be put to good use. > > James One of the nice things about Python is that the syntax is relatively simple, and words are generally favored over punctuation. There's lots of punctuation which is not currently used, but that doesn't mean it's a good idea to go off inventing meanings for it. I supposed we could have: foo->bar ==> foo.__arrrow__(bar) foo$bar ==> foo.__dollar__(bar) foo#bar ==> foo.__hash__(bar) foo::bar ==> foo.__scope__(bar) and so on down the list of non-alphanumeric characters, but the result wouldn't be anything most of us would recognize as Python. |