Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How does "import pythoncom" find the right files?

$
0
0

NB: I know the proper solution is just to do pip install pywin32 and let everything be done automatically, but here this question is about the internals of pythoncom.

When doing import pythoncom, it works, but:

  • in "C:\Python38\Lib\site-packages\pythoncom.py", there is import pywintypes, but no pywintypes.py or .pyd or .dll is present in the site-packages directory. How can it "magically" find pywintypes?

  • when doing print(pythoncom.__file__), we see:

    'C:\\Python38\\lib\\site-packages\\pywin32_system32\\pythoncom38.dll'

    How is this stunning behaviour possible internally? (i.e. pythoncom.py that we imported is now recognized as another file, a .dll)

  • Also, pythoncom.py contains:

    # Magic utility that "redirects" to pythoncomxx.dllimport pywintypespywintypes.__import_pywin32_system_module__("pythoncom", globals())

What and where is this (I quote) "magic utility" that redirects to pythoncomxx.dll?

I don't see where this utility is called when doing just import pythoncom.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>