[issue41899] Poor example for Element.remove()

2020-10-01 Thread Stefan Behnel
Stefan Behnel added the comment: Closing as duplicate of issue 41891. Let's keep the discussion there. -- nosy: +scoder resolution: -> duplicate stage: -> resolved status: open -> closed ___ Python tracker

[issue41899] Poor example for Element.remove()

2020-10-01 Thread Stefan Behnel
Change by Stefan Behnel : -- Removed message: https://bugs.python.org/msg377740 ___ Python tracker ___ ___ Python-bugs-list mailing

[issue41899] Poor example for Element.remove()

2020-10-01 Thread Stefan Behnel
Stefan Behnel added the comment: Closing as duplicate of issue 41892. Let's keep the discussion there. -- ___ Python tracker ___

[issue41899] Poor example for Element.remove()

2020-09-30 Thread WoodyWoo
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

[issue41899] Poor example for Element.remove()

2020-09-30 Thread Eric V. Smith
Eric V. Smith added the comment: As you've seen, the example is correct. I made the same mistake earlier today. For others: see also #41891 for a suggestion to improve the documentation. As was pointed out in that issue, it's generally true in Python that you should not mutate a sequence

[issue41899] Poor example for Element.remove()

2020-09-30 Thread WoodyWoo
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. -- ___ Python

[issue41899] Poor example for Element.remove()

2020-09-30 Thread WoodyWoo
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 5 2011

[issue41899] Poor example for Element.remove()

2020-09-30 Thread WoodyWoo
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 index=index+1 -- ___

[issue41899] Poor example for Element.remove()

2020-09-30 Thread WoodyWoo
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) ... if rank > 50: ...