我正在使用的一些遗留代码有效[代码替换为问题重现代码]:
class foo:
pass
class bar(foo):
def __new__(cls):
global BIZ
if BIZ is not None:
pass
bar()
但是当我把它改成
class foo(object):
然后python打印:
Traceback (most recent call last):
File "test.py", line 11, in <module>
bar()
File "test.py", line 8, in __new__
if BIZ is not None:
NameError: global name 'BIZ' is not defined
为什么是这样?