From: Tobiah on 13 Nov 2009 15:28 > 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.
From: Dave Angel on 14 Nov 2009 10:36 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.
|
Pages: 1 Prev: Choosing GUI Module for Python Next: The ol' [[]] * 500 bug... |