I would like to know the shortest possible way to throw an exception in Python that is not itself a SyntaxError
.
For context, I use an IPython shell for development while editing the source in a different file and use live reload to bring in the changes. To set a break point in code, I usually insert import ipdb; ipdb.set_trace()
to where I need the break point. A different way is triggering an arbitrary Exception
, then use the %debug
magic command on the interpreter to enter post-mortem debugging. I usually use 1/0
for this purpose, which raises a ZeroDivisionError
. SyntaxError
on the other hand is precluded, because then the program would not run at all.
The shortest one I can think of is using a non-existent variable, such as a
, which results in a NameError: name 'a' is not defined
. However this is not guaranteed to always work and requires me to be aware of the current scope. Is there a better way?