First time here? Check out the FAQ!

Revision history  [back]

This snippet doesn't work in the interactive shell because the interactive shell isn't executing code from a file and thus doesn't set the __file__ variable (__file__ is set to the filename where the code comes from). My suggestion is to always run code using __file__ in the debugger (or from the command line). You can also set __file__ in the interactive shell via a simple __file__ = '/path/to/file.py' before executing the snippet.