Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where are the .pyc files?

Tags:

I am a complete newb to python, hence a silly question.

As i understand, upon first execution of a *.py program, byte code is created into *.pyc and used until a change in *.py file.

Where might this *.pyc bytecode be found in a project?

I would think bin, but nothing is there

like image 603
James Raitsev Avatar asked Mar 01 '11 02:03

James Raitsev


2 Answers

A *.pyc file is created for imported modules, and they are placed in the same directory containing the .py file. However... no .pyc file is created for the main script for your program. In other words... if you call "python myscript.py" on the command line, there will be no .pyc file for myscript.py.

This is how Python 2.x behaves. However, in Python 3.x the .pyc files are saved in a __pycache__ directory. See David Glick's answer for details.

[edit: Added note about Python 3.x.]

like image 169
dappawit Avatar answered Oct 23 '22 04:10

dappawit


In Python < 3.2, the .pyc files are placed in the same directory as the .py file.

In Python 3.2, the compiled files are placed in a __pycache__ subdirectory, and are named differently depending on which Python interpreter created them. (This can be useful to people importing the same Python modules from multiple versions of Python.) See http://docs.python.org/dev/whatsnew/3.2.html#pep-3147-pyc-repository-directories for more information.

like image 41
David Glick Avatar answered Oct 23 '22 04:10

David Glick