每当有一个对xml(productline)
的函数调用时,我都会遇到以下错误,但是如果我用file = open('config\\' + productLine + '.xml','r')
替换函数调用,它似乎可以工作,为什么?在
def xml(productLine):
with open('config\\' + productLine + '.xml','r') as f:
return f.read()
def getsanityresults(productline):
xmlfile=xml(productline) // replace with file = open('config\\' + productLine + '.xml','r')
dom = minidom.parse(xmlfile)
data=dom.getElementsByTagName('Sanity_Results')
#print "DATA"
#print data
textnode = data[0].childNodes[0]
testresults=textnode.data
#print testresults
for line in testresults.splitlines():
#print line
line = line.strip('\r,\n')
#print line
line = re.sub(r'(http://[^\s]+|//[^\s]+|\\\\[^\s]+)', r'<a href="\1">\1</a>', line)
print line
#print line
resultslis.append(line)
print resultslis
return resultslis
错误:
^{pr2}$
^{} 需要文件名或文件对象作为参数,但您正在传递文件的内容,请尝试以下操作:
除非您有支持} 在Python中处理xml。在更复杂的情况下,您可能需要更python和^{} 支持它的API,因此您不需要学习两次。在
minidom
的特定需求,否则请使用^{有两个变量,它们的名称略有不同:
有}(大写
productline
(小写l
)和{L
)。在如果在这两种情况下使用相同的变量,则可能会看到更一致的结果。在
相关问题 更多 >
编程相关推荐