我正在从soapui运行selenium python测试来读取文件。当我从命令行运行代码时,一切似乎都正常。但是当我从soapui运行时,它似乎无法找到该文件。
这是我的代码。我相信我需要指定完整路径,但是有一种方法可以定义路径,所以每次调用此函数时我都不必硬拷贝完整路径。
file_name = XMLAuto_al_log.txt
with open(file_name) as f:
with open(outputFileName, 'w') as f1:
for line in f:
if searchText in line:
line = line.rstrip()
object_id = line.split('=')[2]
f1.write(object_id + '\n')
答案 0 :(得分:1)
这个怎么样?
import os.path
directory = ("C:/my/directory/")
file_name = ("XMLAuto_al_log.txt")
path = os.path.join(directory + file_name)