473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

__brace__ (PEP?)

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/
Jul 19 '05 #1
6 1072
James Stroud <js*****@mbi.ucla.edu> wrote:
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.
Jul 19 '05 #2
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

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
Jul 19 '05 #3
In article <ma**************************************@python.o rg>,
James Stroud <js*****@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.
Jul 19 '05 #4
Roy Smith wrote:
foo->bar ==> foo.__arrrow__(bar)
foo$bar ==> foo.__dollar__(bar)
foo#bar ==> foo.__hash__(bar)
foo::bar ==> foo.__scope__(bar)
I'm strongly in favor for the arrow ( but with two "r" only ). The
question is simply: for what?
and so on down the list of non-alphanumeric characters, but the result wouldn't be anything most of us would recognize as Python.


After many sleepless nights reading all the comments and flames about
@decorators I finally came up using them.

Ciao,
Kay

Jul 19 '05 #5
"Kay Schluehr" <ka**********@gmx.net> wrote:
Roy Smith wrote:
foo->bar ==> foo.__arrrow__(bar)
foo$bar ==> foo.__dollar__(bar)
foo#bar ==> foo.__hash__(bar)
foo::bar ==> foo.__scope__(bar)


I'm strongly in favor for the arrow ( but with two "r" only ). The
question is simply: for what?


I'm confused. You're strongly in favor of a piece of punctuation even
though you don't have any idea what it might be used for?
Jul 19 '05 #6
Roy Smith wrote:
"Kay Schluehr" <ka**********@gmx.net> wrote:
Roy Smith wrote:
foo->bar ==> foo.__arrrow__(bar)
foo$bar ==> foo.__dollar__(bar)
foo#bar ==> foo.__hash__(bar)
foo::bar ==> foo.__scope__(bar)
I'm strongly in favor for the arrow ( but with two "r" only ). The
question is simply: for what?


I'm confused. You're strongly in favor of a piece of punctuation

even though you don't have any idea what it might be used for?


Shurely I was joking. I could imagine a few purposes most likely arrows
of some category. That's what You depicted using the "==>" arrow, that
translates some infix operator expression into it's method description.
Arrows are some kind of 2-tuples that express a transition and which
are "left-exact" i.e. there must be at most a right value to some left
value.

Example:

(foo->bar) -> foo.__arrow__(bar)

This is a recursive definition of the arrow which could be further
expanded:

((foo->bar) -> foo.__arrow__(bar)) ->
foo.__arrow__(bar).__arrow__(foo.__arrow__(bar))

etc.

But something intrigues me and that is the prevalence of "foo" above
"bar" i.e. the preimage above the image. I would like to see that one
starts with the binary relation as the primary concept. A relation
should be instantiated by two classes. Let be Rel(A,B) some relation
created from classes A and B. The instances of Rel(A,B) would be arrows
from A to B depicted as arrow diagrams:

foo->bar -> rel.__arrow__(foo,bar)

There is no absolute meaning of the arrow foo->bar, because it reflects
only the particular relation instance rel.

Besides this I guess Guido wants to use the arrow in the context of
"optional static type declarations" for declaring the return type. I
don't like this optional static stuff but the arrow is playing a role
also in this proposal.

Ciao,
Kay

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Christoph Becker-Freyseng | last post by:
Hello, recently there was a lot discussion about a new Path-class. So Gerrit Holl started to write a pre-PEP http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html We tried to...
45
by: Edward K. Ream | last post by:
Hello all, First of all, my present state of mind re pep 318 is one of sheepish confusion. I suspect pep 318 will not affect Leo significantly, but I am most surprised that an apparently...
27
by: John Roth | last post by:
PEP 263 is marked finished in the PEP index, however I haven't seen the specified Phase 2 in the list of changes for 2.4 which is when I expected it. Did phase 2 get cancelled, or is it just not...
15
by: Nick Coghlan | last post by:
Python 2.4's -m command line switch only works for modules directly on sys.path. Trying to use it with modules inside packages will fail with a "Module not found" error. This PEP aims to fix that...
14
by: Marcin Ciura | last post by:
Here is a pre-PEP about print that I wrote recently. Please let me know what is the community's opinion on it. Cheers, Marcin PEP: XXX Title: Print Without Intervening Space Version:...
8
by: Micah Elliott | last post by:
I also have this living as a wiki <http://tracos.org/codetag/wiki/Pep> if people would like to add comments there. I might try to capture there feedback from this group anyway. First try at a PEP...
2
by: Bryan Olson | last post by:
Though I tried to submit a (pre-) PEP in the proper form through the proper channels, it has disappeared into the ether. In building a class that supports Python's slicing interface, ...
77
by: Ben Finney | last post by:
Howdy all, PEP 354: Enumerations in Python has been accepted as a draft PEP. The current version can be viewed online: <URL:http://www.python.org/peps/pep-0354.html> Here is the...
4
by: dustin | last post by:
I've been hacking away on this PEP for a while, and there has been some related discussion on python-dev that went into the PEP: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.