我需要一些帮助。我在使用python连接字符串时遇到一些错误。错误如下所示。
错误:
appstr='<location name="'+ re.escape(location_name) +'"><room id="'+ re.escape(num) + '"><roomname>+'re.escape(rname)'+</roomname><noseats>+'re.escape(seat)'+</noseats><projectorscreen>+'re.escape(projector)'+</projectorscreen><videoconf>+'re.escape(video)'+</videoconf></room></location>'
^
SyntaxError: invalid syntax
我正在解释下面的代码。
def some(request):
if request.method == 'POST':
serch=request.POST.get('searchby')
location_name = request.POST.get('lname')
rname = request.POST.get('rname')
seat = request.POST.get('seat')
projector = request.POST.get('projector')
video = request.POST.get('video')
num=str(random.randint(100000000000,999999999999))
if serch == 'Default':
doc = m.parse("roomlist.xml")
root=doc.getElementsByTagName("roomlist")
valeurs = doc.getElementsByTagName("roomlist")[0]
element = doc.createElement("location")
element.setAttribute("name" , location_name)
el1 = element.appendChild(doc.createElement("room"))
el1.setAttribute("id", num)
el2=el1.appendChild(doc.createElement("roomname"))
el2.appendChild(doc.createTextNode(rname))
el3=el1.appendChild(doc.createElement("noseats"))
el3.appendChild(doc.createTextNode(seat))
el4=el1.appendChild(doc.createElement("projectorscreen"))
el4.appendChild(doc.createTextNode(projector))
el5=el1.appendChild(doc.createElement("videoconf"))
el5.appendChild(doc.createTextNode(video))
valeurs.appendChild(element)
doc.writexml(open("roomlist.xml","w"))
if serch == 'code':
file1 = open("roomlist.xml","r")
flstr = file1.replace("</roomlist>", "")
appstr='<location name="'+ re.escape(location_name) +'"><room id="'+ re.escape(num) + '"><roomname>+'re.escape(rname)'+</roomname><noseats>+'re.escape(seat)'+</noseats><projectorscreen>+'re.escape(projector)'+</projectorscreen><videoconf>+'re.escape(video)'+</videoconf></room></location>'
wstr = flstr + appstr + '</roomlist>'
file1.close()
wfile=open("roomlist.xml","w")
wfile.write(wstr)
return render(request, 'booking/bmr.html', {})
这里我需要将数据写入一个现有文件。请帮我解决这个错误。