[Python-de] immer ausgeführte statement

Georg Mischler schorsch at schorsch.com
Tue Mar 27 10:00:29 EST 2001


Josef Cihal wrote:

> Hallo Leute!!!
>
> Wiesst bitte jemanden, wie kann ich einen statement an der Ende des Codes
> immer durchzuführen???
> Etwas ähnliches wie finally in der Schleife.
>
> Z.B.:
>
> statement 1
> statement 2
>
> error oder sys.exit([1])
>
> statement 3
> statement 4
>
>
> "finally":
>   statement 10
>
> Also ich brauche das statement 10 durchgeführt werde, auch trotzdem dass es
> zu einem error
> (sys.exit() kommt und es geht nicht weiter)


Anhand des Python Reference Manuals (7.4 The try statement):

  The try...finally form specifies a `cleanup' handler. The try
  clause is executed. When no exception occurs, the finally
  clause is executed. When an exception occurs in the try clause,
  the exception is temporarily saved, the finally clause is
  executed, and then the saved exception is re-raised. If the
  finally clause raises another exception or executes a return,
  break or continue statement, the saved exception is lost. The
  exception information is not available to the program during
  execution of the finally clause.

Daraus folgt:

try:
    statement 1
    statement 2
    statement 3
    statement 4
finally:
    statement 10


Viel Spass!

-schorsch

-- 
Georg Mischler  --  simulations developer  --  schorsch at schorsch.com
+schorsch.com+  --  lighting design tools  --  http://www.schorsch.com/




More information about the Python-de mailing list