Out-dated compiled modules (*.pyc)?

A

Anastasios Hatzis

Hi folks,

how can I prevent Python from adding or using *.pyc files if executing a
Python module? I have the strong feeling that the interpreter uses
out-dated pyc file instead more recent py files. At least I already had
some cases where application behaviour changed only by removing the
*.pyc files from the app directory, and in all these cases I interpreted
the difference in code changes I already saved in py files but which had
no effect before removing their pyc versions. I'm not very happy on
deleting pyc files before each execution.

I know there is an -o option for turning on optimization (pyo). In doc I
could not found a hint to an option to turn off pyc compilation -- or at
least forcing the interpreter to use py files only.

I'm working with Python 2.4.2 on WinXP, Eclipse 3.2 with PyDev 1.2.2

Thanks for your help!

Anastasios
 
S

Simon Forman

Anastasios said:
Hi folks,

how can I prevent Python from adding or using *.pyc files if executing a
Python module? I have the strong feeling that the interpreter uses
out-dated pyc file instead more recent py files. At least I already had
some cases where application behaviour changed only by removing the
*.pyc files from the app directory, and in all these cases I interpreted
the difference in code changes I already saved in py files but which had
no effect before removing their pyc versions. I'm not very happy on
deleting pyc files before each execution.

I know there is an -o option for turning on optimization (pyo). In doc I
could not found a hint to an option to turn off pyc compilation -- or at
least forcing the interpreter to use py files only.

I'm working with Python 2.4.2 on WinXP, Eclipse 3.2 with PyDev 1.2.2

Thanks for your help!

Anastasios

The interpeter will always use the newer .py files in preference to
older.pyc files, overwriting the .pyc files with newer versions.

However, if your interpreter is re-importing a module without either
re-starting (the interpreter) or reloading()'ing the module, it will
use the loaded version in the sys.modules cache. This used to happen
in IDLE before it was given the ability to run the interpreter in a
separate subprocess. Now it automatically restarts the interpreter. I
don't know whether Eclipse has this problem but it might.

There are at least three ways of dealing with this: 1) Restart the
interpreter (manually or through some IDE option), 2) call reload() on
your modules, or 3) del the modules from sys.modules before
re-importing them.

Peace,
~Simon
 
D

Dennis Lee Bieber

Hi folks,

how can I prevent Python from adding or using *.pyc files if executing a

Delete the .pyc files from the directory, then make the directory
read-only...
Python module? I have the strong feeling that the interpreter uses
out-dated pyc file instead more recent py files. At least I already had

Normally, Python compares the date stamps of the files (and maybe
some internal magic values) and only rebuilds the .pyc if the .py is
newer.
deleting pyc files before each execution.
I've never had to...
I'm working with Python 2.4.2 on WinXP, Eclipse 3.2 with PyDev 1.2.2
However, there was period of time when, as I recall, the ActiveState
Python installer was putting .pyc (and .pyo) files in front .py in the
list of executable extensions... But that should only affect entering a
name at the command line

c:> module

would run module.pyc before finding module.py
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 
C

Cliff Wells

Normally, Python compares the date stamps of the files (and maybe
some internal magic values) and only rebuilds the .pyc if the .py is
newer.

Perhaps the OP should check both the system date on his PC and the
timestamp on the pyc files in question.

Cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top