英文:
How to tell python to run a .py file when both a .pyc and .py file are present?
问题
如何告诉Python在文件夹中同时存在.py和.pyc文件时使用.py文件?
英文:
I have a project that I have compiled into .pyc files for security, but I want to be able to drop a .py file into my project for debugging purposes as necessary. How can I tell python to use a .py file if both the .py and .pyc files are present in a folder?
i.e. I have:
main:
|
run.pyc
/src/
|
dependency1.pyc
dependency2.pyc
dependency2.py
dependency3.pyc
and when both dependency2.pyc and dependency2.py are in /src/ I want run.pyc to use dependency2.py.
答案1
得分: 1
关于调试。
根据Python文档:
当源文件与一个遗留的pyc文件并存时,Python会忽略该pyc文件。换句话说,如果在foo.py文件旁边存在一个foo.pyc文件,那么在所有情况下都会忽略pyc文件。
在你的情况下,run.py 应该使用 dependency2.py 并忽略相关的 pyc 文件,这将允许你进行调试。
如果这不起作用,尝试暂时将编译后的文件 dependency2.pyc 移出目录。
英文:
With respect to debugging.
From Python docs:
> Python will ignore all legacy pyc files when a source file exists next to it. In other words, if a foo.pyc file exists next to the foo.py file, the pyc file will be ignored in all cases
In your case, run.py should be using dependency2.py and ignoring the associated pyc, which in turn should allow you to debug.
If that's not happening, try to temporarily move the compiled file dependency2.pyc out of the directory.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论