gpt4 book ai didi

python - 我收到错误 "print("Connected to %s on port %s"% (address, port)) ^ SyntaxError : invalid syntax"

转载 作者:太空宇宙 更新时间:2023-11-03 17:16:36 25 4
gpt4 key购买 nike

import socket
import re
import sys
import logging
from __future__ import print_function
def check_server(address, port):
#Create a TCP Socket
s = socket.socket()
print("Attempting to connect to %s on port %s" % (address, port))
try:
s.connect((address, port)
print("Connected to %s on port %s" % (address, port))
return True
except socket.error, e;
print("Connection to %s on port %s failed: %s" % (address, port, e))
return False

if __name__ == '__main__':
from optparse import OptionParser
parser = OptionParser()

parser.add_option("-a", "--address", dest="address", default='localhost', help="ADDRESS for server", metavar="ADDRESS")
parser.add_option("-p", "--port", dest="port", type="int", default=10001, help="PORT for server", metavar="PORT")

(options, arg) = parser.parse_args()
print 'options: %s, args: %s' % (options, args)
check = check_server(options.address, options.port)
print 'check_server returned %s' % check

sys.exit(not check)

最佳答案

替换以下代码

    try:    
s.connect((address, port)
print("Connected to %s on port %s" % (address, port))
return True
except socket.error, e;
print("Connection to %s on port %s failed: %s" % (address, port, e))
return False

    try:    
s.connect((address, port))
print("Connected to %s on port %s" % (address, port))
return True
except socket.error, e;
print("Connection to %s on port %s failed: %s" % (address, port, e))
return False

关于python - 我收到错误 "print("Connected to %s on port %s"% (address, port)) ^ SyntaxError : invalid syntax",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33603284/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com