NameError raised เมื่ออ้างถึงชื่อที่ไม่มีใน scope ปัจจุบัน
ตัวอย่าง
import sys
try:
def foo():
print(magnolia) # undefined
foo()
except NameError as e:
print(e)
print(sys.exc_type)
ผลลัพธ์
global name 'magnolia' is not defined