What's the function location that reads the cached .pyc file from disk.

dieter dieter at handshake.de
Tue Sep 16 02:04:54 EDT 2014


Shiyao Ma <i at introo.me> writes:

> what's the location of the function that reads the .pyc file ?
>
> I bet it should lie in somewhere in
> https://hg.python.org/cpython/file/322ee2f2e922/Lib/importlib
>
> But what's the actual location?

Maybe, you look at the "importlib" source?

Note: the function you search is likely implemented in C.
Finally, you will likely need to look at the C code.


> Btw, why I need it?
> I want to know the structure of a .pyc file. Of course the function
> that reads the .pyc must know something about it.
> (I am aware of the structure of a typical .pyc file from some clicks
> of google pages, but I am interested in the *source* and the most
> authoritative answer, aka, the source code).

In documentation relative to the "marshal" module (internally used
for ".pyc" files), I have read that the details may vary between
Python versions. As "mashal" is used for ".pyc" files, the same likely
applies to ".pyc" files as well. Thus, do not depend too closely
on the things you may find by code inspection.




More information about the Python-list mailing list