Why aren't my jython "* $ py.class" files updated with code changes after I moved them to another package?

I initially had all my modules in one package. I recently created a subpackage in the source package and moved several modules into it. My src folder and two package folders are in my PYTHONPATH.

Since I moved these modules, the changes I make to their .py files do not seem to fall into the generated * $ py.class files, which I believe will ultimately run based on what print __FILE__ spits out.

The .class files are located in the directory of the top-level package, which, I believe, is due to the fact that the first place from which they were imported is inside the module that is in this package. Therefore, I think they are in the right place.

Moving the modules back to the top-level package makes the problem missed, but forced use of all the modules in one package is hardly a solution. Is there anything I need to do to β€œregister" the module as part of the package, other than its presence in the folder with __init__.py ?

Note. The rest of this question is just the symptoms that led me to conclude that the .class files are not updated when the .py files change. You can probably skip it if you are a person: p

I put a bunch of spaces at the beginning of the function, and when I find it, the cursor follows where the code was.

Here is the code that the IDE shows me:

enter image description here

and here are the local vars (note that self has nothing to do):

enter image description here

After I find a couple of lines, here is the code (pay attention to the cursor position): enter image description here and local residents:

enter image description here

Note that now self has id and updatePeriod bound, so these first 2 lines of code after the space are explicitly executed.

If I completely delete the .py file (stick to it on the desktop or something like that), then obviously the IDE cannot find it, so I can’t miss it, but the program works based on what code was used to be (there are some obvious changes that I can say are not working).

Finally, the change dates in the corresponding * $ py.class files are about 4.5 hours, despite all the driving I have done with recent .py files in the last hour or 2.

+8
python jython pydev
source share
3 answers

Compiled Python files are not automatically deleted when .py is deleted. Since they are in $PYTHONPATH in front of your subpackages, they are executed, and since there is no .py for them, they will be used and they will never be updated. The only solution is to manually delete them.

PyDev seems to add confusion by actually interpreting the source code.

+4
source share

I think there are 2 questions here:

  • When you move the file, $py.class not restored:

This is probably because you run the file as the main entry ... If I remember correctly, $py.class only generated when the file is imported (i.e. not for your __main__ module) and only if the code really was changed (I'm not sure how Jython decides that it was changed - maybe file time, but I could be wrong here).

The best solution for this would be to remove $ py.class when moving the file and its corresponding $ py.class (e.g. moving a folder), so you can be 100% sure that Jython will never pick it up.

PyDev can help you: select a folder in PyDev Package Explorer > PyDev > Remove *.pyc, *.pyo and *$py.class Files .

  • $py.class files without the corresponding .py file

PyDev actually handles this correctly for .pyc files (i.e.: removes .pyc when the .py file is no longer available). I am modifying PyDev to handle this for $py.class files too (so if you get night time for 3-4 hours, it should work: see http://pydev.org/download.html for instructions - until then you can delete manually as described above).

+1
source share

I had the same question and did some tests.
I know this topic is a little older, but still I would like to add something here.

$py.class files $py.class only created and updated when a .py class imported somewhere. If the .py file is executed with execfile() , then the $py.class file is not created or updated.

+1
source share

All Articles