How to make Python interpreter a little more strict?
Tim Chase
python.list at tim.thechases.com
Sun Mar 27 16:32:36 EDT 2016
On 2016-03-27 14:28, Steven D'Aprano wrote:
> > So intrigued by this question I tried the following
> > def fnc( n ):
> > print "fnc called with parameter '%d'" % n
> > return n
> >
> > for i in range(0,5):
> > if i%2 == 0:
> > fnc
> > next
> > print i
> >
> > and got the same result as the OP
>
> In this case, the two lines "fnc" and "next" simply look up the
> function names, but without actually calling them. They're not
> quite "no-ops", since they can fail and raise NameError if the name
> doesn't exist, but otherwise they might as well be no-ops.
Which is actually useful. I've got some 2.4 code that reads
try:
any
except NameError:
def any(...):
...
(with a similar block for all() )
I don't want to call any() or all(), I simply want to test whether
they exist.
-tkc
More information about the Python-list
mailing list