DEV Community

Discussion on: A peek inside Python — The How What and Why of Bytecode

Collapse
lachlaneagling profile image
Lachlan Eagling Author

Hi Govinda,

Apologies about the slow reply, have been very busy over the holiday period.

Yes, the bytecode is physically generated into files with the extension .pyc. These are then stored in the __pycache__ directory, these files are what the Python runtime actually executes when a program runs.

Collapse
mpgovinda profile image
Govinda Malavipathirana

Hi Lachlan,

Thanks for replying. As far as I know '.pyc' create only if we import module(s). So let say I'm not import anything but write everything inside the same module, So what would happen to the 'physical byte code' or '.pyc'. Does it even create, where I can find it?

Thread Thread
lachlaneagling profile image
Lachlan Eagling Author

Hi Govinda,

You are right, if no modules are imported I believe the byte code is generated on the fly and not actually saved to disk at all.