[Python-Dev] __file__

Nick Coghlan ncoghlan at gmail.com
Thu Feb 4 10:47:54 CET 2010


Brett Cannon wrote:
> But what does "expected location" mean? If I am importing foo.bar
> where foo.__path__ has multiple path entries, which one is supposed to
> be used to set the hypothetical location of source for __file__? I
> guess going with the first one would be somewhat reasonable, but it's
> definitely a guess.

No, it wouldn't be a guess, it would be based on where the compiled
bytecode was actually found (wherever in foo.__path__ that may have
been). So __file__ would be the same regardless of whether or not the
source code was actually physically present or not. __compiled__ would
be set only if the code being executed was read from that file rather
than from __file__.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------


More information about the Python-Dev mailing list