我在 Python 3.3.2 中遇到了这两个错误:
import os
path="D:\\Data\\MDF Testing\\MDF 4 -Bangalore\\Bangalore Testing"
os.chdir(path)
for file in os.listdir("."):
if file.endswith(".doc"):
print('FileName is ', file)
def testcasenames(file):
nlines = 0
lookup="Test procedures"
procnames=[]
temp=[]
'''Open a doc file and try to get the names of the various test procedures:'''
f = open(file, 'r')
for line in f:
val=int(nlines)+1
if (lookup in line):
val1=int(nlines)
elif(line(int(val))!=" ") and line(int(val1))==lookup):
temp=line.split('.')
procnames.append(temp[1])
else:
continue
return procnames
filename="MDF_Bng_Test.doc"
testcasenames(filename)
Traceback (most recent call last):
File "D:/Data/Python files/MS_Word_Python.py", line 34, in <module>
testcasenames(filename)
File "D:/Data/Python files/MS_Word_Python.py", line 25, in testcasenames
elif(line(val)!=" " and line(val1)==lookup):
TypeError: 'str' object is not callable
这个想法是只有在我在测试文档文件(MDF_Bng_Test.doc)中循环时获得“测试程序”部分之后才获得测试程序名称,然后我复制所有测试程序名称(T_Proc_2.1,S_Proc_2.2。 ..) 在它之下。
前任:
1.1.1 Test objectives
1.Obj 1.1
2.Obj 1.2
3.Obj 1.3
4.Obj 1.4
**2.1.1 Test procedures
1.T_Proc_2.1
2.S_Proc_2.2
3.M_Proc_2.3
4.N_Proc_2.4**
3.1.1 Test References
1.Refer_3.1
2.Refer_3.2
3.Refer_3.3