我正在使用此链接中的服务器和客户端程序:http://www.bogotobogo.com/python/python_network_programming_tcp_server_client_chat_server_chat_client_select.php
当我运行客户端时遇到以下错误:
Traceback (most recent call last):
File "client.py", line 26, in client
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
io.UnsupportedOperation: fileno
Run Code Online (Sandbox Code Playgroud)
我正在使用Python 3,但我已经使用print来改变所有行Python 2 to 3.
这是代码:
while 1:
socket_list = [sys.stdin, s]
# Get the list sockets which are readable
read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
Run Code Online (Sandbox Code Playgroud) 研究:
https://github.com/faucamp/python-gsmmodem/issues/39
https://docs.python.org/2/howto/sockets.html
这是我的完整错误输出:
Traceback (most recent call last):
File "/home/promitheas/Desktop/virus/socket1/socket1.py", line 20, in <module>
createSocket()
File "/home/promitheas/Desktop/virus/socket1/socket1.py", line 15, in createSocket
ServerSock.bind((socket.gethostname(), servPort))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)
码:
import socket
# Acquiring the local public IP address
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 0))
# Defining some variables
servIpAddr = s.getsockname()[0]
servPort = ''
while ((len(servPort) < 4)): # and (len(servPort) > 65535)
servPort = raw_input("Enter server port. Must be …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已被问过几次,但没有一个能够为我提供解决方案.我看了这些:
我所要做的就是为"生存游戏"创建两个类,就像一个非常糟糕的我的世界版本.Bellow是这两个类的完整代码:
class Player:
'''
Actions directly relating to the player/character.
'''
def __init__(self, name):
self.name = name
self.health = 10
self.shelter = False
def eat(self, food):
self.food = Food
if (food == 'apple'):
Food().apple()
elif (food == 'pork'):
Food().pork()
elif (food == 'beef'):
Food().beef()
elif (food == 'stew'):
Food().stew()
class Food:
'''
Available foods and their properties.
'''
player = Player()
def __init__(self):
useless = 1
Amount.apple = 0
Amount.pork = 0
Amount.beef = …Run Code Online (Sandbox Code Playgroud)