<p>我正在编写一个程序来查找适配器,并创建了一个名为“Adapter”的类。当我传入两个参数时,IDLE给了我一个错误,说我传入了三个!下面是代码和堆栈跟踪:</p>
<pre><code>#This is the adapter class for the adapter finder script
class Adapter:
side1 = (None,None)
side2 = (None,None)
'''The class that holds both sides of the adapter'''
def __init__((pType1,pMF1),(pType2,pMF2)):
'''Initiate the adapter.
Keyword Arguments:
pType1 -- The passed type of one side of the adapter. ex: BNC, RCA
pMF1 -- The passed gender of pType1. ex: m, f
pType2 -- The passed type of one side of the adapter. ex: BNC, RCA
pMF2 -- The passed gender of pType2. ex: m, f
'''
print 'assigining now'
side1 = (pType1,pMF1)
print side1
side2 = (pType2,pMF2)
print side2
sideX = ('rca','m')
sideY = ('bnc','f')
x = Adapter(sideX,sideY)
print x.side1
print x.side2
</code></pre>
<p>错误:
<code>Traceback (most recent call last):
File "C:\Users\Cody\Documents\Code\Python\Adapter Finder\adapter.py", line 28, in <module>
x = Adapter(sideX,sideY)
TypeError: __init__() takes exactly 2 arguments (3 given)</code></p>
<p>我不明白问题是什么,因为我只输入了两个参数!</p>
<p>编辑:我是python语言的新手,虽然我懂Java。
我将此页用作教程:<a href="http://docs.python.org/tutorial/classes.html" rel="nofollow noreferrer">http://docs.python.org/tutorial/classes.html</a></p>