有时 PyDev 无法将 .py 文件识别为 python 源文件

发布于 2024-12-14 08:23:15 字数 388 浏览 1 评论 0原文

有时,当我在 PyDev Package Explorer 中打开 python 文件(.py 扩展名)时,该文件会作为纯文本文件打开 - 没有语法突出显示、断点设置和所有其他出色的 PyDev 功能。我看不到同一文件夹中其他文件的任何差异。当我创建另一个 .py 文件时(这次 PyDev 意识到它是一个 Python 源文件),添加带有断点的 import unrecognized_file 语句,调试该文件并选择“步入”无法识别的文件,它突然变得很好,我可以看到语法突出显示,并且可以使用断点等等。

关闭 unrecognized_file 并重新打开它后,它又回到哑文本模式,我无法使用 PyDev 功能。

关于出了什么问题的任何线索吗?判断一个文件是python文件还是文本文件的算法是什么?

Sometimes when I open a python file (.py extension) in the PyDev Package Explorer, that file is opened as a plain text file - without syntax highlighting, breakpoint setting and all the other great PyDev features. I cannot see any differences to other files in the same folder. When I create another .py file (this time PyDev realises that it is a python source file), add an import unrecognised_file statement with a breakpoint, debug the file and choose to "Step into" the unrecognised file, it suddenly comes good and I can see syntax highlighting and can use breakpoints and all.

After closing the unrecognised_file and re-opening it, it is back to dumb text mode an I can't use the PyDev features.

Any clues about what is going wrong? What is the algorithm for determining if a file is a python file or a text file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2024-12-21 08:23:15

如果发生这种情况(并且文件关联将“Python 编辑器”标记为首选项中的默认值),您可以右键单击该文件并执行“使用 > 其他打开方式”,然后从列表中选择“Python 编辑器”。

稍后应该为该文件保留该设置(可能发生的情况是您以文本形式打开该文件,并且 Eclipse 保留该文件,因此,使用 PyDev 编辑器再次打开应该使关联再次正确)。

ps:调试器强制使用 PyDev 编辑器打开文件,但是当您通过 PyDev Package Explorer 打开文件时,该设置不会保留(这就是它在调试会话中起作用的原因)。

If this happens (and the association for file marks "Python editor" as the default in the preferences), you can right-click the file and do "open with > other" and choose "Python editor" from the list.

That setting should be persisted for that file later on (what could've happened is that you opened the file as text and Eclipse persists that, so, opening again with the PyDev editor should make the association correct again).

p.s.: the debugger forces opening files with the PyDev editor, but that setting is not persisted as when you open the file through the PyDev Package Explorer (that's why it works when you're in a debug session).

好听的两个字的网名 2024-12-21 08:23:15

您可以检查文件关联选项。

在 Eclipse 中可以在 Window -> 中找到它。首选项,常规 ->编辑->文件关联。

默认情况下,*.py 文件应具有 Python 编辑器。

You may check File Associations option.

In Eclipse it can be found in Window -> Preferences, General -> Editors -> File Associations.

*.py files should have Python Editor by default.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文