So legen Sie das Textfeld ElementTree Element im Konstruktor fest
Wie setze ich das Textfeld von ElementTree Element in seinem Konstruktor? Oder warum ist im folgenden Code der zweite Ausdruck von root.text None?
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
Hier die Ausgabe:
<period units="months">6</period>
6
<period text="6" units="months" />
None
<period units="months">6</period>
6