Вот мой код:Не может cacth NameError в питоне
from SimPy.Simulation import *
class Message(Process):
def arrive(self, destination):
yield hold, self, 2
try:
print "%s %s going to %s" % (now(), self.name, destination.name)
self.interrupt(destination)
except NameError, x:
print "%s is out of reach" % x
То, что я хочу сделать, это распечатать этот пункт назначения недоступен, когда его имя не существует, но я все еще получаю обычно ошибка python:
Traceback (most recent call last):
File "<pyshell#22>", line 1, in <module>
message.arrive(node2)
NameError: name 'node2' is not defined
Где вы называете 'message.arrive (node2)'? –
Я просто написал его в оболочке – tobi
Тогда вы не определили 'node2'. –