[Tutor] Need all values from while loop - only receiving one

Alan Gauld alan.gauld at yahoo.co.uk
Tue Jul 3 20:15:40 EDT 2018


On 04/07/18 01:08, Alan Gauld via Tutor wrote:

> # Now the main code just needs the outer loops:
> tree = ET.parse(r'\\DealData.xml')
> root = tree.getroot()
> deals = []
> for deal in root.findall("Deals"):
>     for dl in deal.findall("Deal"):
>         deals.append( Deal(dl) )
> 
>         if dl.id == "706880":
>            print(dl)  #uses __str__() to create string

Sorry, that last loop should be like this:

     for xml_dl in deal.findall("Deal"):
         theDeal = Deal(xml_dl)
         deals.append( theDeal )

         if theDeal.id == "706880":
            print(theDeal)  #uses __str__() to create string


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list