Komodo IDE: '__file__' is not defined when debugging

Trent Mick trentm at ActiveState.com
Tue Jan 3 20:40:06 CET 2006

[fortepianissimo wrote]
> This is a question to all of you who use Komodo IDE for development:
> when I tried to debug my script which uses __file__ to get the absolute
> path to the file, Komodo complained that the variable is not defined.
> Anyway to work around this? (without changing the code)
> Or if I need to change the code, how do I achieve the same thing I
> wanted? Thanks in advance!

The problem is that when you run your script under the debugger (same
thing with pdb.py) __file__ isn't set automatically because running a
Python script with Python's execfile() (which is what Komodo debugger
does) works slightly differently that what Python's main() does to run a
Python script. One of the differences is the setting of __file__.

(Side note: I'm not sure if this should be a Python bug or not. The
intention of under what conditions  __file__ should be set are not clear
from the Python docs. From a quick poke I think it may be possible that
__file__ not getting set via execfile() is a bug that was introduced
with pythonrun.c changes when nested scopes were added a while back).

We've started a bug for this on Komodo:

...and Shane just fixed it. I.e. Subsequent releases of Komodo will have
this fixed: __file__ will be set in the main module.

Until that release, workarounds:
1. get the main script path from sys.argv[0]; or
2. apply the patch (to .../dbgp/client.py in your Komodo install) that
   Shane attached to that bug to your Komodo installation.

Thanks for mentioning the bug.


Trent Mick
trentm at activestate.com

More information about the Python-list mailing list