<p>在过去的一周里,我一直在玩Python,在向类方法传递4个参数时遇到了一个问题。你知道吗</p>
<p><strong>下面是在其类中定义的类方法:</strong></p>
<pre><code>class Line:
locx0 = 0
locy0 = 0
locx1 = 0
locy1 = 0
def __init__(self):
print'<<Line __init__()>>'
def setLineCoordinates(locx0, locy0, locx1, locy1):
self.locx0 = locx0
self.locy0 = locy0
self.locx1 = locx1
self.locy1 = locy1
def getLineCoordinatesX0():
return self.x0
def getLineCoordinatesY0():
return self.y0
def getLineCoordinatesX1():
return self.x1
def getLineCoordinatesY0():
return self.y0
</code></pre>
<p><strong>我在这里调用class方法:</strong></p>
<pre><code>def LineDepot():
x0 = None
x1 = None
y0 = None
y1 = None
line = Line()
print"Please enter starting and ending coordinates "
print"If no value is entered, then it will be assumed that the coordinate value is zero "
x0 = int(input('Enter value for initial x coordiante : '))
y0 = int(input('Enter value for initial y coordiante : '))
x1 = int(input('Enter value for end x coordiante :'))
y1 = int(input('Enter value for end y coordiante :'))
line.setLineCoordinates(x0, y0, x1, y1)
</code></pre>
<p><strong>这是我在输出中遇到的错误:</strong></p>
<pre><code>Please make a selection from the following menu...
1.Create a new Line
2.View current lines
3.View logs
4.Mail line info or logs
5.View summary of line stats
6.Exit this program
Menu Selection:1
<<Line __init__()>>
Please enter starting and ending coordinates
If no value is entered, then it will be assumed that the coordinate value is zero
Enter value for initial x coordiante : 1
Enter value for initial y coordiante : 2
Enter value for end x coordiante :3
Enter value for end y coordiante :4
Traceback (most recent call last):
File "./linear.line.py", line 107, in <module>
Main()
File "./linear.line.py", line 15, in Main
Menu()
File "./linear.line.py", line 52, in Menu
LineDepot()
File "./linear.line.py", line 32, in LineDepot
line.setLineCoordinates(x0, y0, x1, y1)
TypeError: setLineCoordinates() takes exactly 4 arguments (5 given)
</code></pre>
<p>我一直想弄明白为什么当我通过4个参数时,翻译是
告诉我我想通过5级考试。你知道吗</p>
<p>我已经并将继续研究这个问题。你知道吗</p>
<p>任何帮助都将不胜感激。
谢谢!!!你知道吗</p>