WoodyWoo added the comment:
Could I say the mutable sequence containing not the object but the pointer like
C++.
So they can changed in def functions.
--
___
Python tracker
<https://bugs.python.org/issue41
WoodyWoo added the comment:
Could I say the mutable sequence containing not the object but the pointer like
C++.
So they can changed in def functions.
--
___
Python tracker
<https://bugs.python.org/issue41
WoodyWoo added the comment:
@eric.smith @scoder @serhiy.storchaka Thank U all.
I get what to do,and still think the "for in" structure should rebuilding.
All three methods:
import xml.etree.ElementTree as ET
xmlstr=\
r'''
2
WoodyWoo added the comment:
The docs should specially tell that when need root.remove(child) must works
with "for child in root.findall()".
And my code with "while if continue" could make root.insert(index,newchild)
easily.
--
__
WoodyWoo added the comment:
My fault.
"for country in root.findall('country')“ is not working as same as "for country
in root"
all 3 method below:
import xml.etree.ElementTree as ET
xmlstr=\
r'''
2
2008
141100
WoodyWoo added the comment:
#new code to avoid an err
index=0
count=len(root.findall("./*"))
while index 50:
root.remove(root[index])
index=index+0
count=count-1 # avoid index err
continue
ind
New submission from WoodyWoo :
We can remove elements using Element.remove(). Let’s say we want to remove all
countries with a rank higher than 50:
>>>
>>> for country in root.findall('country'):
... rank = int(country.find('rank').text)
...
WoodyWoo added the comment:
I think "for each in list" should not work by index,but should work by pointer
like thing,could be a list of pointers.
When the "for each in list" was acting,the pointers list would be fixed,and you
need not to worry about
WoodyWoo added the comment:
Only that makes "for each in list" literally.
--
___
Python tracker
<https://bugs.python.org/issue41892>
___
___
Python-b
WoodyWoo added the comment:
I'm green hand in Coding.
But I think the problem caused by "for each in list".
Anything changed in "list" should not act at once,but should act when "for end"
or break.
--
___
Pytho
Change by WoodyWoo :
--
title: use both "for" and "ElementTree.remove" has a index bug -> use both "for
in" and "ElementTree.remove" has a index bug
___
Python t
New submission from WoodyWoo :
#Just run it in Python v3.8.6 of win7 32bit
import xml.etree.ElementTree as ET
xmlstr='''
'''
etroot = ET.fromstring(xmlstr)
for ELEMchild in etroot:
if ELEMchild.get("no") == "1" :
etroot
12 matches
Mail list logo