run all scripts in sub-directory as subroutines?

Dave Angel davea at
Sat Nov 14 16:36:21 CET 2009

Tobiah wrote:
>> This works fine, but in the sub-modules the sys.path appropriately
>> returns the same as from the parent, I want them to know their own file
>> names. How?? I can pass it to them, but wondered if there is a more
>> self-sufficient way for a module to know from where it was invoked.
> I like the idea of passing the information to the module.
> Probably by setting a global variable into it.
As ryles pointed out in this thread, over a month ago, that's already 
there.  The system loader creates a global variable __file__ with the 
full path to the module.  So any module can see exactly where it was 
loaded from.

More information about the Python-list mailing list