Re: what the heck this code is doing?

2016-07-01 Thread Basant Dagar

Awesome. Thank you John for the prompt response. 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what the heck this code is doing?

2016-07-01 Thread Basant Dagar
On Friday, July 1, 2016 at 2:06:28 PM UTC-4, John Gordon wrote:
> In <3bbddafc-dcd6-4d5c-84f4-94077b5bc...@googlegroups.com> Basant Dagar 
>  writes:
> 
> > def lookup(d, keyval):
> > found = False
> > for child in d:
> > if found : return child.text
> > if child.tag == 'key' and child.text == keyval :
> > found = True
> > return None
> 
> > trackID = lookup(entry, 'Track ID')
> 
> > Below is the main part of input xml file data, it passes to lookup function:
> 
> > Track ID369
> 
> > what I don't get is. How in the world it returns value 369 for the variable 
> > 'trackID'??
> 
> It loops through the child items in entry, looking for one with a
> 'key' value of 'Track ID'.  If it finds one, it sets found=True and
> loops one more time, returning the text of the *next* child element.
> 
> It depends on the 'key' element being directly followed by the 'integer'
> element within entry.
> 
> -- 
> John Gordon   A is for Amy, who fell down the stairs
> gor...@panix.com  B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"

Awesome. Thank you John for the prompt response.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: what the heck this code is doing?

2016-07-01 Thread John Gordon
In <3bbddafc-dcd6-4d5c-84f4-94077b5bc...@googlegroups.com> Basant Dagar 
 writes:

> def lookup(d, keyval):
> found = False
> for child in d:
> if found : return child.text
> if child.tag == 'key' and child.text == keyval :
> found = True
> return None

> trackID = lookup(entry, 'Track ID')

> Below is the main part of input xml file data, it passes to lookup function:

> Track ID369

> what I don't get is. How in the world it returns value 369 for the variable 
> 'trackID'??

It loops through the child items in entry, looking for one with a
'key' value of 'Track ID'.  If it finds one, it sets found=True and
loops one more time, returning the text of the *next* child element.

It depends on the 'key' element being directly followed by the 'integer'
element within entry.

-- 
John Gordon   A is for Amy, who fell down the stairs
gor...@panix.com  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


what the heck this code is doing?

2016-07-01 Thread Basant Dagar
#See below code:

def lookup(d, keyval):
found = False
for child in d:
if found : return child.text
if child.tag == 'key' and child.text == keyval :
found = True
return None

trackID = lookup(entry, 'Track ID')

 
Below is the main part of input xml file data, it passes to lookup function:

Track ID369

what I don't get is. How in the world it returns value 369 for the variable 
'trackID'??
-- 
https://mail.python.org/mailman/listinfo/python-list