'for every' and 'for any'
Andrew Dalke
dalke at dalkescientific.com
Sun May 26 15:00:11 EDT 2002
jepler at unpythonic.net:
>this is equivalent to
> bool([None for x in args if not isinstance(x, str)])
Not quite the same as the original poster's request, which
raises a TypeError, and raises it at the first error location
without continuing to scan the rest of the args. It's also
harder to understand this as a list comprehension. Jeff's
style, of
for x in args:
if not isinstance(x, str):
raise TypeError, "arguments must be of type str"
is what I consider to tbe the prefered style, except I think the
exception should be raised
raise TypeError("arguments must be of type str")
(That preferred change occured, I believe, in Python 1.4.)
>> valid = i>0 for every i in vector
>
>This is equivalent to
> not [None for i in vector if not i > 0]
Jeff's equivalent also stopped at the firt match while yours scans
everything. That may or may not be part of the consideration of
the original poster.
Oren Tirosh:
>> The words 'any' and 'every' can be non-reserved keywords (like the word
'as'
>> in "import foo as bar"). They are valid only after the keyword 'for'
when
>> it's used in a non-statement context.
Jython supports something like this, to allow "print" as a method name.
This is important because there are a lot of Java classes with that name,
as it isn't a keyword in Java. As I recall, this came up recently in
python-dev and Guido was against implementing it for CPython, because
he didn't want a word which was a keyword in places and a variable in
others. This change won't happen.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list