[Python-Dev] Pre-PEP: Unifying try-except and try-finally
François Pinard
pinard at iro.umontreal.ca
Fri May 6 17:35:16 CEST 2005
[Guido van Rossum]
> [Nick Coghlan]
> > > What does a try statement with neither an except clause nor a
> > > finally clause mean?
> [Greg Ewing]
>
> > I guess it would mean the same as
> > if 1:
> > ...
> I strongly disagree with this. [...]
Allow me a quick comment on this issue.
It happens once in a while that I want to comment out the except clauses
of a try statement, when I want the traceback of the inner raising, for
debugging purposes. Syntax forces me to also comment the `try:' line,
and indent out the lines following the `try:' line. And of course, the
converse operation once debugging is done. This is slightly heavy.
At a few places, Python is helpful for such editorial things, for
example, allowing a spurious trailing comma at end of lists, dicts,
tuples. `pass' is also useful as a place holder for commented code.
At least, the new proposed syntax would allow for some:
finally:
pass
addendum when commenting except clauses, simplifying the editing job for
the `try:' line and those following.
P.S. - Another detail, while on this subject. On the first message I've read
on this topic, the original poster wrote something like:
f = None
try:
f = action1(...)
...
finally:
if f is not None:
action2(f)
The proposed syntax did not repeat this little part about "None", quoted
above, so suggesting an over-good feeling about syntax efficiency.
While nice, the syntax still does not solve this detail, which occurs
frequently in my experience. Oh, I do not have solutions to offer, but
it might be worth a thought from the mighty thinkers of this list :-)
--
François Pinard http://pinard.progiciels-bpi.ca
More information about the Python-Dev
mailing list