2.2 features
Tim Peters
tim.one at home.com
Fri Aug 3 15:17:31 EDT 2001
[Paul Prescod]
> ...
> Yes "x in class y" would be a boolean expression elsewhere but that's
> just like the current exception syntax which looks like a tuple
> constructor but isn't really. Either we try to reuse syntax or we don't.
The current exception syntax *does* accept a tuple constructor: the special
case you're "seeing" doesn't actually exist. For example,
try:
# whatever
except (OverflowError, ZeroDivisionError):
pass
is exactly the same as:
myexceptions = (OverflowError, ZeroDivisionError)
try:
# whatever
except myexceptions:
pass
except's first paramater can be an arbitrarily-deeply nested tuple, and it
doesn't matter how it's constructed; it's simply *common* to write a tuple
literal. Combine it with some backward-compatibility hacks, and you can do
some, umm, "interesting" things with this:
>>> def stringin(s, stuple):
... try:
... raise s
... except stuple:
... return 1
... else:
... return 0
...
>>> stringin('b', ('a', ('c', 'b'), 'd'))
1
>>> stringin('b', ('a', ('c', 'e'), 'd'))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in stringin
b
>>>
indeed-that's-the-fastest-way-to-search-a-deeply-nested-tuple-ly
y'rs - tim
More information about the Python-list
mailing list