SyntaxError: invalid syntax print "get remote configure failed: %s, %s" %

 Python  3.9
 print "get remote configure failed: %s, %s" % (REMOTE_JSON_FILE, e.message) 

SyntaxError: invalid syntax

def GetClangConfigFromRemote():
    global g_clang_format_config
    res = None
    try:
        res = urllib.request.urlopen(REMOTE_JSON_FILE, timeout=3.0)
    except Exception as e:
        print "get remote configure failed: %s, %s" % (REMOTE_JSON_FILE, e.message)
        print "use local default config instead"
        g_clang_format_config = DEFAULT_CONFIG
        return True

    jsonDict = None
    try:
        jsonDict = json.loads(res.read())
    except Exception as e:
        print "parse json failed:%s" % e.message
        print "use local default config instead"
        g_clang_format_config = DEFAULT_CONFIG
        return True
    g_clang_format_config = jsonDict["C_Cpp.clang_format_style"]
    return True

运行结果及报错内容

print "get remote configure failed: %s, %s" % (REMOTE_JSON_FILE, e.message)
^
SyntaxError: invalid syntax

print是函数,加括号

def GetClangConfigFromRemote():
    global g_clang_format_config
    res = None
    try:
        res = urllib.request.urlopen(REMOTE_JSON_FILE, timeout=3.0)
    except Exception as e:
        print ("get remote configure failed: %s, %s" % (REMOTE_JSON_FILE, e.message))
        print ("use local default config instead")
        g_clang_format_config = DEFAULT_CONFIG
        return True
 
    jsonDict = None
    try:
        jsonDict = json.loads(res.read())
    except Exception as e:
        print ("parse json failed:%s" % e.message)
        print ("use local default config instead")
        g_clang_format_config = DEFAULT_CONFIG
        return True
    g_clang_format_config = jsonDict["C_Cpp.clang_format_style"]
    return True
 

你现在的代码用的python2的语法,要么你更换python2,要么你要用python3的写法:

 print("get remote configure failed: %s, %s")%(REMOTE_JSON_FILE, e.message) 

这是python2.X 版本上的写法,如果你的环境是python3.9 那就改成print()函数形式,字符串格式化建议使用format函数

 print "get remote configure failed: %s, %s" % (REMOTE_JSON_FILE, e.message)

# python3.9环境下建议这样写
  print( "get remote configure failed: {}, {}".format(REMOTE_JSON_FILE, e.message))

python3环境用的python2的语法
把print改成print()就不会报语法错误了