(Apr-24-2024, 05:33 AM)Pedroski55 Wrote: What does xmlparser.ParseFile(f) want for f?Still work with some changes over to Python 3,as mention bye Gribouillis need
Is the module too old?
'rb'
# coexpat.py # # An example of pushing XML events generated by the low-level expat # XML library into coroutines. import xml.parsers.expat def expat_parse(f,target): parser = xml.parsers.expat.ParserCreate() parser.buffer_size = 65536 parser.buffer_text = True # parser.returns_unicode = False parser.StartElementHandler = \ lambda name,attrs: target.send(('start',(name,attrs))) parser.EndElementHandler = \ lambda name: target.send(('end',name)) parser.CharacterDataHandler = \ lambda data: target.send(('text',data)) parser.ParseFile(f) # Example. This uses the bus processing code from earlier with no changes. if __name__ == '__main__': from buses import * with open("allroutes.xml", 'rb') as file: expat_parse(file, buses_to_dicts( filter_on_field("route", "22", filter_on_field("direction", "North Bound", bus_locations()))))
Output:22,1485,"North Bound",41.880481123924255,-87.62948191165924
22,1629,"North Bound",42.01851969751819,-87.6730209876751
22,1489,"North Bound",41.962393500588156,-87.66610128229314
.....
Other changes in the two files this code calles,is just over to print() function.Eg in coroutine.py line 21
print line,
is in Python 3 print(line, end='')
.