Python 认为我传递的参数比我实际传递的参数多?
尝试在 Python 中设置一些基本的套接字代码(好吧,Jython,但我认为这与这里无关)。
import socket
class Foo(object):
def __init__(self):
#some other init code here
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect("localhost", 2057)
s.send("Testing 1,2,3...")
data = s.recv()
s.close()
print data
它告诉我:
s.connect("localhost", 2057) 文件“
”,第 1 行,连接中 类型错误:connect() 恰好需要 2 个参数(给定 3 个参数)
我感觉有一些非常简单的东西正在盯着我的脸,但我不知道我做错了什么。
Trying to set up some basic socket code in Python (well, Jython, but I don't think that's relevant here).
import socket
class Foo(object):
def __init__(self):
#some other init code here
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect("localhost", 2057)
s.send("Testing 1,2,3...")
data = s.recv()
s.close()
print data
It tells me:
s.connect("localhost", 2057) File "<string>", line 1, in connect TypeError: connect() takes exactly 2 arguments (3 given)
I get the feeling something really simple is staring me in the face, but I can't tell what I'm doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(6)
温馨耳语2024-12-05 18:56:27
socket.connect 只接受 1 个参数,即地址,如果自计数则接受 2 个参数。
地址的格式在第四段中说明, http://docs.python.org/library /socket.html
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您必须将元组传递给
connect()
方法。第一个(隐式)参数预期是 self,第二个是元组。
You have to pass a Tuple to
connect()
method.The first (implicit) argument expected is
self
, the second is the Tuple.