How can module determine its own path?

Dave Angel davea at ieee.org
Sat Oct 31 01:26:51 EDT 2009


Stef Mientki wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">Robert 
> Kern wrote:
>> On 2009-10-30 12:19 PM, kj wrote:
>>> How can a module determine the path of the file that defines it?
>>> (Note that this is, in the general case, different from sys.argv[0].)
>>
>> __file__
>>
> but for modules launched with execfile, __file__ doesn't exists.
>
> cheers,
> Stef
>
The way I read the docs, execfile() doesn't create a module, so this is 
irrelevant.  Effectively it adds to the current module, or to whatever 
the global() and local() dictionary define.

I haven't experimented with it (as the doc says, it's used rarely), so 
if I'm wrong, please correct me.

DaveA




More information about the Python-list mailing list