473,320 Members | 1,969 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,320 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 1953
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:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.