저는 Python을 처음 사용하고 XML을 구문 분석하는 프로그램을 작성하는 데 매우 익숙합니다. 난 내가 'NodeList' object has no attribute 'len'
오류가 발생 NodeList 수 있다고 생각에 .len()
호출하려고 할 때 문제가 발생합니다. documentation 말한다 때문에 나에게 정말 놀라운 일이다 :Python에서 XML을 구문 분석하고 'NodeList'객체에 'len'속성이 없습니다.
, 파이썬 DOM 인터페이스는 약간의 추가 지원이있는 NodeList 객체가 파이썬 시퀀스로 사용할 수 있도록 제공해야합니다.
translationDom = parse(xmlFileName) testFunction(translationDom)
내가 싶지 않아 ...
Main()
에서 다음import xml.dom.minidom def testFunction(translationDOM): textCollection = translationDOM.getElementsByTagName("onscreen_text") for onscreenText in textCollection: print textCollection.len()
및 모든 NodeList를 구현
여기
내 코드의 렌()에 대한 지원을 포함해야 여기 내 전체 XML을 게시하십시오 (방대한). 그러나 비슷한 블록이 있습니다 :
<onscreen_text>
<source id="2036" unique_name="blah" should_be_translated="True">
....
</onscreen_text>
여기에 전체 오류 텍스트입니다 :
File "trophytool.py", line 155, in <module>
main()
File "trophytool.py", line 134, in main
testFunction(translationDom)
File "trophytool.py", line 64, in testFunction
print textCollection.len()
AttributeError: 'NodeList' object has no attribute 'len'
당신은 그것을 발견 <onscreen_text>
태그의 수를 인쇄 할 것 같아,하지만하지 않습니다. 왜 이런거야?
보십시오'textCollection.length' – Torious