By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

Findnext Not found.

P: 1
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)

Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
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.