[英]How to fix a "invalid syntax" error in my Python code?
@Klaus D. 是对的,你的__init__
每边需要两个下划线,而不是 1。确保你的类下的方法正确缩进也是一个好主意。
#!/usr/bin/python
import socket
class Listener:
def __init__(self, ip, port):
listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind((ip, port))
listener.listen(0)
print("Waiting for connections....")
self.connection, address = listener.accept()
print("Got a connection from " + str(address))
def execute_remotely(self, command):
self.connection.send(command)
return self.connection.recv(1024)
def run(self):
while True:
command = raw_input(">>")
result = self.execute_remotely(command)
print(result)
myListener = Listener("10.0.2.15", 8080)
myListener.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.