gpt4 book ai didi

python - Python语法错误

转载 作者:行者123 更新时间:2023-12-03 08:32:29 24 4
gpt4 key购买 nike

我想知道我在语法上做错了什么。
我正在尝试执行一个脚本,它返回了很多错误,其中大多数是try-exception(示例1,2,3),而示例4则有问题...
有人在这里看到问题吗?
范例1:

def post(self, data):
post_data = json.dumps(data)
if VERBOSE:
sys.stderr.write("\nDEBUG: POST data: %r\n" % post_data)
try:
# Watch out: we must provide the verify keyword to every individual request call!
# Else it will be overwritten by the REQUESTS_CA_BUNDLE env variable
raw_response = self._session.post(self.base_url,
data=post_data,
verify=self._session.verify)
except () if DEBUG else Exception, exc:
sys.stderr.write("ERROR: %s\n" % exc)
raise SkipMBean(exc)

return validate_response(raw_response)
范例2:
def _get_queries(do_search, inst, itemspec, title, path, mbean):
if not do_search:
return [(mbean + "/" + path, title, itemspec)]

try:
value = fetch_var(inst, "search", mbean)
except () if DEBUG else SkipMBean:
return []

try:
paths = make_item_list((), value, "")[0][1]
except IndexError:
return []

return [("%s/%s" % (urllib2.quote(mbean_exp), path), path, itemspec) for mbean_exp in paths]
范例3:
def _process_queries(inst, queries):
for mbean_path, title, itemspec in queries:
try:
for item, out_title, value in fetch_metric(inst, mbean_path, title, itemspec):
yield item, out_title, value
except (IOError, socket.timeout):
raise SkipInstance()
except SkipMBean:
continue
except () if DEBUG else Exception:
continue
范例4:
def generate_values(inst, var_list):
for var in var_list:
mbean, path, title, itemspec, do_search = var[:5]
value_type = var[5] if len(var) >= 6 else None

queries = _get_queries(do_search, inst, itemspec, title, path, mbean)

for item, title, value in _process_queries(inst, queries):
if value_type:
yield item, title, value, value_type
else:
yield item, title, value
这是它发出的错误之一,例如1:
File "jolokia_metrics", line 342
except () if DEBUG else Exception, exc:
^
SyntaxError: invalid syntax

最佳答案

except () if DEBUG else Exception, exc: 
except () if DEBUG else SkipMBean:
except () if DEBUG else Exception:
较新版本的Python不支持此语法。
https://docs.python.org/3/tutorial/errors.html

关于python - Python语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65626520/

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