469,294 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,294 developers. It's quick & easy.

Findnext Not found.

Hello experts,

i found the program on youtube and try to figure out the bus towards to north longitude and latitude near to dave using xml file but it showing me an error....
lat = float(bus.findnext('lat'))

AttributeError: 'xml.etree.ElementTree.Element' object as no attribute 'findnext'


Here's the code,
Expand|Select|Wrap|Line Numbers
  1. import urllib
  2.  
  3. daves_latitude = 41.98062
  4. daves_longitude = -87.668452
  5.  
  6. from xml.etree.ElementTree import parse
  7. doc = parse('rt22.xml')
  8.  
  9. for bus in doc.findall('bus'):
  10.     lat = float(bus.findnext('lat'))
  11.     if lat > daves_latitude:
  12.         direction = bus.findnext('d')
  13.         if direction.startwith('North'):
  14.             busid = bus.findnext('id')
  15.             print (busid,lat)
  16.  
here is the xml file link.
http://ctabustracker.com/bustime/map...e.jsp?route=22




Thank you in advance..
Apr 3 '15 #1

✓ answered by bvdet

As the traceback indicates, bus has no "findnext" method. It has a "findall" method which returns a list.
Expand|Select|Wrap|Line Numbers
  1. from xml.etree.ElementTree import parse
  2.  
  3. daves_latitude = 41.98062
  4. daves_longitude = -87.668452
  5.  
  6. doc = parse("rt22.xml")
  7.  
  8. for bus in doc.findall('bus'):
  9.     lat = float(bus.findall('lat')[0].text)
  10.     if lat > daves_latitude:
  11.         direction = bus.findall('d')[0].text
  12.         if direction.startswith('North'):
  13.             busid = bus.findall('id')[0]
  14.             print (busid,lat)

1 1776
bvdet
2,851 Expert Mod 2GB
As the traceback indicates, bus has no "findnext" method. It has a "findall" method which returns a list.
Expand|Select|Wrap|Line Numbers
  1. from xml.etree.ElementTree import parse
  2.  
  3. daves_latitude = 41.98062
  4. daves_longitude = -87.668452
  5.  
  6. doc = parse("rt22.xml")
  7.  
  8. for bus in doc.findall('bus'):
  9.     lat = float(bus.findall('lat')[0].text)
  10.     if lat > daves_latitude:
  11.         direction = bus.findall('d')[0].text
  12.         if direction.startswith('North'):
  13.             busid = bus.findall('id')[0]
  14.             print (busid,lat)
Apr 3 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Tom | last post: by
9 posts views Thread by John Hernry | last post: by
14 posts views Thread by NormD | last post: by
1 post views Thread by shiznaw | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.