在Eclipse for Python项目

时间:2017-10-20 16:34:16

标签: python eclipse eclipse-neon

我在Eclipse Neon中有一个足够小的Python项目并且不断收到相同的错误,但找不到有关如何解决的正确文档。在我的主要我需要调用位于另一个文件夹中的文件。我收到的错误是IOError:[Errno 2]没有这样的文件或目录:

我正在尝试使用的文件夹(XML_TXT)中有一个空的 init .py文件。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

看起来Groovy导入正常,否则你会得到一个ImportError。 IOError表示找不到“test.txt”。该文件存在吗?

如果文件路径相对于运行脚本的位置,它将起作用。例如,如果test.txt在文件夹中

Groovy("folder_name/test.txt")

如果需要,您也可以进入目录结构,例如

Groovy("../folder_name/test.txt")

或者,如果您希望能够从任何地方运行该文件,您可以让python为您提供文件的绝对路径。

import os

filename = os.path.join(os.path.dirname(__file__), 'folder_name/test.txt')
u = Groovy(filename)
相关问题