我想捕获一个特定的ValueError,而不仅仅是任何ValueError.
我试过这样的事情:
try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except: ValueError, 'For STRING = ’WPF’, this machine is not a wind machine.':
pass
Run Code Online (Sandbox Code Playgroud)
但它引发了一个SyntaxError:无法分配给文字.
然后我尝试了:
try: maquina['WPF'] = macdat(ibus, id, 'WPF')
except ValueError, e:
if e != 'For STRING = ’WPF’, this machine is not a wind machine.':
raise ValueError, e
Run Code Online (Sandbox Code Playgroud)
但它提出了例外,即使它是我想要避免的那个.
python ×1