ElementTree 요소의 텍스트 필드를 해당 생성자에서 설정하는 방법은 무엇입니까? 또는 아래 코드에서 root.text의 두 번째 인쇄가 표시되지 않는 이유는 무엇입니까? 여기생성자에서 ElementTree 요소 텍스트 필드를 설정하는 방법
import xml.etree.ElementTree as ET
root = ET.fromstring("<period units='months'>6</period>")
ET.dump(root)
print root.text
root=ET.Element('period', {'units': 'months'}, text='6')
ET.dump(root)
print root.text
root=ET.Element('period', {'units': 'months'})
root.text = '6'
ET.dump(root)
print root.text
출력 :
<period units="months">6</period>
6
<period text="6" units="months" />
None
<period units="months">6</period>
6
감사합니다! (나는 문서 대신 코드를 읽어야했다!) –