from socket import *
s = socket(AF_INET, SOCK_DGRAM) #创建套接字
addr = ('192.168.1.17', 8080) #准备接收方地址
data = input("请输入:")
s.sendto(data.encode(),addr)
#发送数据时,python3需要将字符串转成byte
#encode(‘utf-8’)# 用utf-8对数据进行编码,获得bytes类型对象
#decode()反过来
s.close()
C:\Users\pcl\venv\Scripts\python.exe "C:/Users/pcl/.1aPython all exercise/网络通信/UDP发送.py"
Traceback (most recent call last):
File "C:\Users\pcl\.1aPython all exercise\网络通信\UDP发送.py", line 1, in <module>
from socket import *
File "C:\Users\pcl\.1aPython all exercise\网络通信\socket.py", line 3, in <module>
s=socket(socket.AF_INET,socket.SOCK_STREAM)
AttributeError: partially initialized module 'socket' has no attribute 'AF_INET' (most likely due to a circular import)
Process finished with exit code 1
老师 这个为什么会报错啊