This is a bad idea, but:
def handle_nameerror(list_to_set, *varnames):
for i in varnames:
try:
list_to_set.append(globals()[i])
except NameError:
list_to_set.append(None)
will work.
2
solved How to use NameError to define a variable in Python