Controlling the passing of data
Peter Otten
__peter__ at web.de
Thu Apr 28 09:40:23 EDT 2016
Sayth Renshaw wrote:
> In my file here I needed to traverse and modify the XML file I don't want
> to restore it or put it in a new variable or other format I just want to
> alter it and let it flow onto the list comprehensions as they were.
That looks like an arbitrary limitation to me. It's a bit like
"I want to repair my car with this big hammer".
> In particular here I am taking the id from race and putting it into the
> children of each race called nomination.
>
> I have put a comment above the new code which is causing the difficulty.
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.
More information about the Python-list
mailing list