简体   繁体   中英

Variable in subelement python elementtree

I use elementtree in python. I need to use a variable instead text in the subelement .text

Example:

ET.SubElement(pv,"title", lang="en").text = "ertyuiiuyghgvc" 

i need

ET.SubElement(pv,"title", lang="en").text = myvariable[1]

any help?

yes, my variable is also a string, the error is instead the xml file reproduce like this:

<?xml version="1.0"?>-<dt>-<city id="paris"><display-name lang="fr">paris</display-name></city>-<it route="paris" stop="20181006000000 +0000" start="20181005230000 +0000"><title lang="fr">ertyuiiuyghgvc</title></it>

print only:

ertyuiiuyghgvc

only if i use a variable instead "mytext"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM