Necessity of ``pass''

grahamclemo at my-deja.com grahamclemo at my-deja.com
Wed Aug 25 07:18:19 EDT 1999


> A similar problem occurs in try/except statements.  If you want
temporarily
> disable the try/except so you can see what exception is being raised,
you
> have to monkey around with the code a bit.  I've gotten used to using
"if
> 0:" and indenting the code another step with C-c > (I use Emacs):
>
>     if foo:
> 	if 0:
> 	    bar
> 	    baz
>     qux
>
> The try/except issue is a little messier.  You wind up with something
like:
>
>     if 1:
>     #try:
> 	try body
>     else:
>     #except:
> 	except body
>

After a bit of experimentation I found you can replace except: with
except 0: (I doubt anyone has raise 0 in their code) and except
ZeroDivisionError: with except 0:#ZeroDivisionError: etc.
(I'm surprised Python silently accepts *any* value in except statements)

> No language is perfect.  I doubt that eliminating the requirement at
least
> one statement in a block is going to help much.
>
> There are probably syntactic considerations as well.  If you allow
empty
> blocks you probably introduce ambiguities in the language that you'd
have to
> correct somehow.

Allowing empty blocks might cause indentation bugs (confusions about
tab sizes for example) to be silently accepted by the parser.

Besides, any expression that has no effect works, such as 0 or '' or
(), albeit less efficiently (it creates extra bytecodes), if you
*really* can't be bothered to type pass.

There's-more-than-one-way-to-do-nothing'ly y'rs,
Graham Clemo


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




More information about the Python-list mailing list