pre-PEP: Suite-Based Keywords - syntax proposal
Kay Schluehr
kay.schluehr at gmx.net
Sat Apr 16 12:07:09 EDT 2005
The idea is interesting but not unambigously realizable. Maybe one
should introduce some extra syntax for disambiguation and thereby
generalize the proposal.
as <specifier>:
# list of definitions and assignments
Proposed specifiers are dict, tuple, *, ** and func.
- as dict:
conversion into a dictionary
Example:
d = as dict:
doc = "I'm the 'x' property."
def fget(self):
return self.__x
We would get d = {"doc":"I'm the 'x' property.", "fget":fget}
- as **:
conversion into keyword-arguments. This comes close in spirit to the
original proposal
Example:
x = property():
as **:
doc = "I'm the 'x' property."
def fget(self):
return self.__x
- as tuple:
conversion into a tuple. Preserving order.
Example:
t = as tuple:
doc = "I'm the 'x' property."
def fget(self):
return self.__x
>>> t[1]
<function fget at 0x00EC4770>
- as *:
conversion into an argument tuple. Preserving order.
Example:
x = property():
as *:
def get_x():
return self.__x
def set_x(value):
self.__x = value
del_x = None
doc = "I'm the 'x' property."
- as func(*args,**kw):
Anoymus functions. Replacement for lambda. Support for
arbirtray statements?
Examples:
p = as func(x,y): x+y
p(1,2)
i,j = 3,4
if (as func(x,y): x+y) (i,j) > 10:
print True
Ciao,
Kay
More information about the Python-list
mailing list