> > Your actual problem is drowned in too much source code. Can you restate it > in English, optionally with a few small snippets of Python? > > It is not even clear what the code you provide should accomplish once it's > running as desired. > > To give at least one code-related advice: You have a few repetitions of the > following structure > > > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') > > > meet = d('meeting') > > > meetdata = [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] > > You should move the pieces into a function that works for meetings, clubs, > races, and so on. Finally (If I am repeating myself so be it): the occurence > of range(len(something)) in your code is a strong indication that you are > not using Python the way Guido intended it. Iterate over the `something` > directly whenever possible.
Hi Peter > meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') is created to define a list of attr in the XML rather than referencing each attr individually I create a list and pass it into > meetdata = [[meet.eq(i).attr(x) > > for x in meetattrs] for i in range(len(meet))] This list comprehension reads the XML attr by attr using meet = d('meeting') as the call to pyquery to locate the class in the XML and identify the attr's. I do apologise for the lack of output, I asked a question about parsing that I always seem to get wrong over think and then find the solution simpler than I thought. The output is 4 tables of the class and selected attributes eg meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition') from the meeting class of the XML. In order to give flexibility and keep the relational nature they have defined in the table I found when exporting the nominations section via pandas to csv that i had no way to determine which id belonged to each race that is there was no race_id in the nominations to relate back to the race, and also no meeting id in the raceid to relate it back to the meeting. So I wanted to traverse all the classes Meeting, Race and Nomination and insert the id of the class into its direct children only and since there were many races a meeting and many nomnations a race I need to ensure that it is the direct children only. It was otherwise working as parsed output in code supplied using to push to pandas and use its csv write capability. So I inserted for race_el in d('race'): race = pq(race_el) race_id = race.attr('id') for nom_el in race.items('nomination'): res.append((pq(nom_el).attr('raceid', race_id))) which traverses and inserts the race_id into the child nominations. However, my boggles is how to pass this to the list comprehension that was working without changing the data from XML or creating another intermediate step and variable. Just to parse it as it was but with the extra included race_id. Thanks Sayth -- https://mail.python.org/mailman/listinfo/python-list