473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1955
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

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

Similar topics

4
by: Tom | last post by:
Wta is the code structure to put Rst.FindNext in a loop? I'm using what I show below. It works fine but my instinct says it should be in some standard loop rather than using the GoTo structure. ...
9
by: John Hernry | last post by:
I have been watching the dotnet newsgroups for a couple of weeks now and scouring the net looking for a solution to my datagrid find functionality. With no luck. I am hoping that you can help me....
14
by: NormD | last post by:
We have a client-server app using Web Services on an IIS machine. The trace below shows that .NET is searching around for some things (e.g., SystemDrawing.DLL and System.Drawing.EXE) and taking a...
1
Corster
by: Corster | last post by:
I went through a great deal of hassle to figure this out for myself, but now it is complete, I would like to share it with the world! I know afew other people have had trouble with FindFirst and...
1
by: shiznaw | last post by:
How can I attach the findnext method to a spinbutton so that the control can browse through the values of a particular field? Private Sub SpinButton4_SpinUp() Dim mjr As Recordset Set mjr =...
11
by: Poudda | last post by:
Hi there, I'm trying to set up a "find / next / replace" input box, but I have no clue how to make vb do this. Currently my code has a three step process. I have an input box that asks for a...
7
by: BUmed | last post by:
Well, in need to find a record using a command button so I set up a FindRecord in a macro. Now the person wants to be able to find all the records that meet the last name criterian so I thought I...
0
by: savakis | last post by:
Can onyone please help me please. I have duplicate items in column A:A which I find via combobox1. These items are placed in listbox1. I then fill in textbox1 and textbox2 for column C and D, and...
1
by: sora | last post by:
Hi, I've developed a MFC program under VS 6.0. My debugger *was* working fine and I've used it often for my project. Then, one day, the errors below appear and they prevent me from using the...
0
by: bitstreamer | last post by:
Greetings everybody, I'm trying to UNDERSTAND this code. I've already done lots and lots of debugging sessions and I can confirm that the FIND_NEXT routine is never executed. Every file entry...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.