我目前正在为 Python3 中的 Ableton live 11 开发步进音序器。这是我手动从 Python2 转换为 3 的代码。我正在定义一个可能为空也可能不是空的列表,因此我插入了一个检查以使用 if 语句查看列表是否为空,但它不是发现列表为空。这是我当前问题的一些代码:
notes = self._time_step(time).filter_notes(self._clip_notes)
if notes:
most_significant_velocity = max(notes, key=lambda n: n[3])
do something
else:
do something different
我收到以下错误:
2021-11-05T12:18:12.100094: info: RemoteScriptError: most_significant_velocity = max(notes, key=lambda n: n[3])
2021-11-05T12:18:12.100138: info: RemoteScriptError:
2021-11-05T12:18:12.100184: info: RemoteScriptError: ValueError
2021-11-05T12:18:12.100227: info: RemoteScriptError: :
2021-11-05T12:18:12.100271: info: RemoteScriptError: max() arg is an empty sequence
在这种情况下,Notes 是一个空列表,因此“做其他事情”应该是被调用的内容。相反,if 语句没有捕捉到注释是空的。有关如何调试或解决此问题的任何想法?