[Python-Dev] Pre-PEP: Unifying try-except and try-finally

Guido van Rossum gvanrossum at gmail.com
Fri May 6 17:41:32 CEST 2005


[François Pinard]
> 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.

I tend to address this by substituting a different exception. I don't
see the use case common enough to want to allow dangling try-suites.

> 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 :-)

I don't understand your issue here. What is the problem with that
code? Perhaps it ought to be rewritten as

f = action1()
try:
    ...
finally:
    action2(f)

I can't see how this would ever do something different than your version.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list