Movatterモバイル変換


[0]ホーム

URL:


[Python-Dev] Exceptions in LOAD_GLOBAL and LOAD_NAME

Mark Shannonmark at hotpy.org
Thu Feb 23 11:12:13 CET 2012


The code below causes different behaviour for LOAD_GLOBAL and LOAD_NAME.Which is correct?Should exceptions raised in the equality test be converted to a NameError or just propogated?Cheers,Mark.-------------------------------------import sysclass S(str):     passdef eq_except(self, other):     if isinstance(other, str):         raise TypeError("Cannot compare S and str")globals()[S("a")] = 0S.__eq__ = eq_exceptdef f():     print(a)try:     f()except:     print(sys.exc_info()[1])try:     print(a)except:     print(sys.exc_info()[1])----------------------------------Output:TypeError('Cannot compare S and str',)NameError("name 'a' is not defined",)


More information about the Python-Devmailing list

[8]ページ先頭

©2009-2025 Movatter.jp