【发布时间】:2011-10-19 21:57:41
【问题描述】:
我有两个文件,其中一个 test.py 是
import new.py
class Test:
def __init__(self):
return
def run(self):
return 1
if __name__ == "__main__":
one=Test()
one.run()
和新的.py
class New:
def __init__(self):
one.run()
New()
现在当我运行 python test.py 时出现此错误,
Traceback (most recent call last):
File "test.py", line 1, in <module>
import new.py
File "/home/phanindra/Desktop/new.py", line 5, in <module>
New()
File "/home/phanindra/Desktop/new.py", line 3, in __init__
one.run()
NameError: global name 'one' is not defined
但我想在我的 New 中使用这个实例! 我可以这样做吗?
编辑:
我想在 new.py 中访问 test.py 中的变量来做一些处理并将它们返回给 test.py。这不可能吗?
【问题讨论】:
标签: python class initialization