2005年05月27日 星期五 08:31
正在阅读《简明Python教程》,里面讲异常处理中except和finally不能共存, 那么如果要进行异常处理还要进行资源释放该如何操作呢?望指教! 另;java中是可以共存的,如下: File file = null; try { file = new File("xxx.xxx"); ...... } catch (Exception e) { ...... } finally { try { if (file != null) { file.close(); } } catch (Exception e) { } } ****************************** 大連華信計算機技術有限公司 HSW開発センター 劉磊<liul at dhc.com.cn> tel:+86-411-8474-6465 FAX:+86-411-8474-6500 ****************************** -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20050527/e82c00af/attachment.htm
2005年05月27日 星期五 08:42
¼ò½àÃ÷ÁË£¬¸Ðл£¡ ----- Original Message ----- From: "limodou" <limodou at gmail.com> To: <python-chinese at lists.python.cn> Sent: Friday, May 27, 2005 10:35 AM Subject: Re: [python-chinese] ¹ØÓÚtry...except...finall y > ǶÌס£²»Äܹ²´æÊÇ˵²»ÄÜдÔÚÒ»¼¶ÖУ¬È磺 > try: > ... > except: > ... > finally: > ... > > µ«Ç¶Ì×ÊÇ¿ÉÒԵģ¬È磺 > try: > try: > ... > except: > ... > finally: > ... > ÔÚ 05-5-27£¬¢ÀÚ<liul at dhc.com.cn> дµÀ£º >> >> ÕýÔÚÔĶÁ¡¶¼òÃ÷Python½Ì³Ì¡·£¬ÀïÃæ½²Òì³£´¦ÀíÖÐexceptºÍfinally²»Äܹ²´æ£¬ >> ÄÇôÈç¹ûÒª½øÐÐÒì³£´¦Àí»¹Òª½øÐÐ×ÊÔ´ÊͷŸÃÈçºÎ²Ù×÷ÄØ£¿ÍûÖ¸½Ì£¡ >> >> Áí;javaÖÐÊÇ¿ÉÒÔ¹²´æµÄ£¬ÈçÏ£º >> File file = null; >> try { >> file = new File("xxx.xxx"); >> ...... >> } catch (Exception e) { >> ...... >> } finally { >> try { >> if (file != null) { >> file.close(); >> } >> } catch (Exception e) { >> } >> } >> ****************************** >> ´óßBÈAÐÅÓËãC¼¼ÐgÓÐÏÞ¹«Ë¾ >> HSWé_°k¥»¥ó¥¿©` >> ¢ÀÚ<liul at dhc.com.cn> >> tel:+86-411-8474-6465 >> FAX£º+86-411-8474-6500 >> ****************************** >> _______________________________________________ >> python-chinese list >> python-chinese at lists.python.cn >> http://python.cn/mailman/listinfo/python-chinese >> >> >> > > > -- > I like python! > My Donews Blog: http://www.donews.net/limodou > New Google Maillist: http://groups-beta.google.com/group/python-cn > -------------------------------------------------------------------------------- > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese >
2005年05月27日 星期五 09:35
x7bM16GjsrvE3LmytObKx8u1srvE3NC01NrSu7y21tCjrMjno7oKdHJ5OgogICAuLi4KZXhjZXB0 OgogICAuLi4KZmluYWxseToKICAgLi4uCgq1q8e2zNfKx7/J0tS1xKOsyOejugp0cnk6CiAgIHRy eToKICAgICAgLi4uCiAgIGV4Y2VwdDoKICAgICAgLi4uCmZpbmFsbHk6CiAgIC4uLgrU2iAwNS01 LTI3o6yEosDaPGxpdWxAZGhjLmNvbS5jbj4g0LS1wKO6Cj4gIAo+INX91NrUxLbBoba88sP3UHl0 aG9uvcyzzKG3o6zA78PmvbLS7LOjtKbA7dbQZXhjZXB0us1maW5hbGx5srvE3LmytOajrCAKPiDE x8O0yOe5+9KqvfjQ0NLss6O0psDtu7nSqr340NDXytS0ys23xbjDyOe6zrLZ1/fE2KO/zfvWuL3M o6EgCj4gICAKPiDB7TtqYXZh1tDKx7/J0tS5srTmtcSjrMjnz8KjuiAKPiBGaWxlIGZpbGUgPSBu dWxsOyAKPiB0cnkgeyAKPiAgICAgZmlsZSA9IG5ldyBGaWxlKCJ4eHgueHh4Iik7IAo+ICAgICAu Li4uLi4gCj4gfSBjYXRjaCAoRXhjZXB0aW9uIGUpIHsgCj4gICAgIC4uLi4uLiAKPiB9IGZpbmFs bHkgeyAKPiAgICAgdHJ5IHsgICAgCj4gICAgICAgICBpZiAoZmlsZSAhPSBudWxsKSB7IAo+ICAg ICAgIC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