我正在编写一个python脚本,我需要在其中打开“ .txt”文件夹并分析其中的文本。
我已将此“ .txt”文档保存在与Python脚本相同的文件夹中。
但是,当我去打开文件时; file = open("words.txt",'r')
我收到错误消息:No such file or directory: 'words.txt'
。
我不明白为什么会这样?
答案 0 :(得分:2)
Maby,这是因为您当前的工作目录与文件存储的目录不同。尝试提供文件的完整路径
file = open("<full_path>\words.txt",'r')
答案 1 :(得分:0)
希望有帮助。
答案 2 :(得分:0)
这是因为您正在使用的.py
文件的目录与.txt
文件的路径不同。
因此,您需要提及这样的路径:
file = open("C:/User/Desktop/Folder/words.txt", 'r')
答案 3 :(得分:-1)
尝试使用以下一项:public void add inputs(){
// here I will get two elements int the list
List<Webelement> labels = BrowserFactory.getdriver().findElements(By.xPath("//div/label[@class='ng.binding']")
// here I will get two elements related to select in the list
List<Webelement> selectDropdown= BrowserFactory.getdriver().findElements(By.xPath("//div/select[@class='ng-touched']")
for (Webelement label: labels )
{
if (label.getText().equals("Target Environment"))
{
// here I have to click the select(dropdown) of the matched label i.e Target Environement' select class
}
}
}
您在Windows上吗?