我有这个问题,AttributeError: type object 'ElementTree' has no attribute 'tostring'
我不知道什么是错的,我导入到字符串,它不起作用.尝试按照另一个教程,但没有.
有没有其他方法将ElementTree对象转换为XML字符串?
import os
import re
import glob
from xml.dom import minidom
from time import strftime
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
date=strftime("%Y-%m-%dT%H:%M:%S")
os.chdir('/home/guillermo/TclsPy/XML_Level2/')
def prettify(elem):
"""Return a pretty-printed XML string for the Element.
"""
rough_string = ElementTree.tostring(elem, 'utf-8',method="xml" , short_empty_elements=True)
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=" ")
for nameXml in glob.glob("*.xml"):
new_nameXml = re.sub(r'tlmy',r'AUX',nameXml,flags=re.IGNORECASE)
new_nameXml = re.sub('.xml','_AlarmEnabled.xml',new_nameXml, flags=re.IGNORECASE)#new_nameXml.lower().replace('.xml','_AlarmEnabled.xml')
match = re.search(r'TSL_TM_TLMY_(.+).xml', nameXml,flags= re.IGNORECASE )
if match: …
Run Code Online (Sandbox Code Playgroud) 我有这个查询:
$consulta = $this->db->consulta("INSERT INTO prestamo_equipo (id_equipo, id_usuario, fecha_devolucion) VALUES $valor ");
Run Code Online (Sandbox Code Playgroud)
哪里$valor
是('1', '75', 'xs', '2015-12-14'),('1', '75', 'xs', '2015-12-14')
.
$id = $this->db->getInsertId($consulta);
Run Code Online (Sandbox Code Playgroud)
这最后一行,只返回第一个插入ID,而不是另一个,我想要两个插入的id.