【发布时间】:2016-07-29 13:26:52
【问题描述】:
我将三个类分开如下:
file1.py
class one():
def __init__(self):
self.x = 1
self.y = 3
self.h = self.x + self.y
file2.py
from file1 import *
class two():
def __init__(self,coming):
self.get = coming.h+1
file3.py
from file1 import *
from file2 import *
class three():
def __init__(self,f1,f2):
self.v1 = f1.h
self.v2 = f2.get
print(self.v1)
print(self.v2)
k = three(two(one()))
每当我应该运行 file3.py 时,我都需要这样的结果:
> 4
> 5
但是我的代码给出了 file2 没有返回任何值,那么这里是我的错误:
~#python file3.py
Traceback (most recent call last):
File "file3.py", line 10, in <module>
k = three(two(one()))
TypeError: __init__() takes exactly 3 arguments (2 given)
【问题讨论】:
-
您的
three类希望您提供两个参数(第三个是自动传入的self)。
标签: python python-2.7 class python-3.x