[Tutor] When is and isn't "__file__" set?

eryk sun eryksun at gmail.com
Fri Jan 12 18:25:11 EST 2018


On Fri, Jan 12, 2018 at 5:22 PM, Albert-Jan Roskam
<sjeik_appie at hotmail.com> wrote:
> On Jan 11, 2018 03:47, Steven D'Aprano <steve at pearwood.info> wrote:
>>
>> Modules which are loaded from a .dll or .so binary file also should have
>> __file__ set.
>
> And .pyd? I would hope so

A .pyd is a Windows DLL (i.e. PE/COFF shared library). The .pyd type
is associated with the "Python.Extension" program identifier, which
sets a custom descriptive name and icon in Explorer. Sometimes a
Python extension module uses the .dll file extension instead of .pyd.
For example, from PyWin32:

    >>> print(pywintypes.__file__)
    C:\Program Files\Python36\pywintypes36.dll
    >>> print(pythoncom.__file__)
    C:\Program Files\Python36\pythoncom36.dll


More information about the Tutor mailing list