Why no try-except-finally ?

KefX keflimarcusx at aol.comNOSPAM
Wed Nov 5 21:32:19 CET 2003


>Somewhat better style, generally, IMHO, would be to replace "err_code = 1"
>with "raise" in the above.  Consider returning error codes to be a
>parallel (and somewhat obsolescent) way of communicating failures to
>calling code.  Raising an exception should be generally preferred.

I agree with you in general, but this code is in my main() function, and
returning an error code one way or another is the only way to report the error
status to the OS. :)

Instead of this:

if __name__ == '__main__':
    main()

my code does this:

if __name == '__main__':
    sys.exit(main())

I believe Guido suggested that idiom in his blog.

- Kef





More information about the Python-list mailing list