Python:TypeError:*之后的参数必须是一个序列
发布时间:2021-01-17 07:04:19 所属栏目:Python 来源:互联网
导读:我有这段代码,我尝试在新线程中发送UDP数据报 import threading, socketaddress = (localhost, 9999)def send(sock): sock.sendto(Message, address) print sents = socket.socket(socket.AF_INET, socket.SOCK_DG
我有这段代码,我尝试在新线程中发送UDP数据报 import threading,socket address = ("localhost",9999) def send(sock): sock.sendto("Message",address) print "sent" s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) threading.Thread(target=send,args=(s)).start() 但是当我尝试将套接字作为函数的参数时,会抛出一个TypeError异常: Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python2.7/threading.py",line 810,in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py",line 763,in self.__target(*self.__args,**self.__kwargs) TypeError: send() argument after * must be a sequence,not _socketobject 那意味着什么? 解决方法你需要在变量s之后添加一个逗号 –,– .只发送s到args =()试图解包一些参数,而不是发送那个单一的争论.所以你有线程.Thread(target = send,args =(s,)).start() 另外,splat – * – 运算符在this问题中可能很有用,它解释了它的用法和解压缩参数 (编辑:大庆站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python进程间通信--信号Signal
- 具有distinct()的Django order_by()过滤器
- python – 为什么cv2扩展实际上不会影响我的图像?
- ImportError:没有模块名称’matplotlib’Python 3.3
- python – 使用lxml.html提取文本
- python-2.7 – 在Python 2.7中手动构建ConfigParser的深层副
- python – 使用Tensorflow中的多层感知器模型预测文本标签
- python简单的监控脚本-利用socket、psutil阻止远程主机运行
- python – 在Matplotlib中绘制两行之间的角度的最佳方式
- 协程、 事件驱动介绍