Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #107837
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2016-04-28 18:49 -0700 |
| References | (1 earlier) <nft3s8$3ku$1@ger.gmane.org> <mailman.189.1461850832.32212.python-list@python.org> <cf68e844-441c-4498-a730-0c7b08da1ee9@googlegroups.com> <5c94882cb24c441bad13fd122851bd38@seaexchmbx03.olympus.F5Net.com> <mailman.194.1461856753.32212.python-list@python.org> |
| Message-ID | <892ed2df-b5ee-48ba-9cdc-4c05a8f097ab@googlegroups.com> (permalink) |
| Subject | Re: Controlling the passing of data |
| From | Sayth Renshaw <flebber.crue@gmail.com> |
On Friday, 29 April 2016 01:19:28 UTC+10, Dan Strohl wrote:
> If I am reading this correctly... you have something like (you will have to excuse my lack of knowledge about what kinds of information these actually are):
>
> <race id=1>
> <nomination>1234</nomination>
> <meeting>first</meeting>
> </race>
> <race id=2>
> <nomination>5678</nomination>
> <meeting>second</meeting>
> </race>
>
>
> And you want something like:
> nominations = [(1,1234), (2,5678)]
> meetings = [(1,'first'),(2,'second')]
>
> if that is correct, my suggestion is to do something like (this is psudeo code, I didn't look up the exact calls to use):
>
> nomination_list = []
> meeting_list = []
>
> for race_element in xml_file('race'):
> id = race_element.get_attr('id')
> for nomination_element in race_element('nomination'):
> nomination = nomination_element.get_text()
> nomination_list.append((id, nomination))
>
> for meeting_element in race_element('meeting'):
> meeting = meeting_element.get_text()
> meeting_list.append((id, meeting))
>
>
>
>
Yes in essence that is what I am trying to acheive however the XML I have has many attributes like this.
for example this is one nomination.
<nomination number="1" saddlecloth="1" horse="Astern" id="198247" idnumber="" regnumber="" blinkers="0" trainernumber="235" trainersurname="O'Shea" trainerfirstname="John" trainertrack="Agnes Banks/Hawkesbury" rsbtrainername="John O'Shea" jockeynumber="86876" jockeysurname="McDonald" jockeyfirstname="James" barrier="10" weight="56.5" rating="0" description="B C 2 Medaglia D'oro(USA) x Essaouira (Exceed And Excel)" colours="Royal Blue" owners="Godolphin" dob="2013-09-24T00:00:00" age="3" sex="C" career="3-2-0-0 $220750.00" thistrack="1-1-0-0 $68750.00" thisdistance="1-1-0-0 $152000.00" goodtrack="3-2-0-0 $220750.00" heavytrack="0-0-0-0" slowtrack="" deadtrack="" fasttrack="0-0-0-0" firstup="2-2-0-0 $220750.00" secondup="1-0-0-0" mindistancewin="0" maxdistancewin="0" finished="1" weightvariation="0" variedweight="56.5" decimalmargin="0.00" penalty="0" pricestarting="$2.15F" sectional200="0" sectional400="0" sectional600="0" sectional800="0" sectional1200="0" bonusindicator="" />
Therefore I thought that if I tried to do it like the code you posted it would soon become unweildy.
> for race_element in xml_file('race'):
> id = race_element.get_attr('id')
> for nomination_element in race_element('nomination'):
> nomination = nomination_element.get_text()
> nomination_list.append((id, nomination))
So I created a list of the attributes of each class meeting race nomination and then parsed that list through the list comprehension.
On putting out the code though I realised that whilst each class worked I had no way to relate the race to the meeting, the nomination to the race so if I then loaded the csv or created sql to push it to a db it would loose its relation.
So when I say
meetattrs = ('id', 'venue', 'date', 'rail', 'weather', 'trackcondition')
In my thinking this is a table.
Meeting
id
venue
date
rail
weather
trackcondition
There is no foreign key relation to race, so in this question I am saying shouldn't I put the meeting_id as a foreign key into the race attributes before parsing race and then I can have a 'id' in meeting related to the new 'race_id' in race. The id of race would then be put in nomnation before parsing and I would do the same?
Hoping this is clearer, probably a little close to the problem to express it clearly so I apologise for that.
Sayth
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 05:02 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-28 15:40 +0200
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 06:59 -0700
RE: Controlling the passing of data Dan Strohl <D.Strohl@F5.com> - 2016-04-28 15:19 +0000
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-28 18:49 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-29 13:26 +0200
Re: Controlling the passing of data Sayth Renshaw <flebber.crue@gmail.com> - 2016-04-29 06:17 -0700
Re: Controlling the passing of data Peter Otten <__peter__@web.de> - 2016-04-29 13:36 +0200
RE: Controlling the passing of data Dan Strohl <D.Strohl@F5.com> - 2016-04-28 14:40 +0000
Re: Controlling the passing of data Rustom Mody <rustompmody@gmail.com> - 2016-04-28 07:52 -0700
csiph-web