Link to home
Start Free TrialLog in
Avatar of JohnAutoSales
JohnAutoSales

asked on

Getting data from a tuple

Hi there,

I've got a tuple of the following form:

factoryloc = (make , country).
But there are many members in the tuple, i.e.:
factoryloc = ((toyota , japan) , (fiat , italy) , ...... )

I then have an XML file like this:

<garage name="wood road">
  <vehicle make="toyota" model="yaris">
    <note>
      New model - 1 litre Terra
    </note>
   </vehicle>
   <vehicle make="nissan" model="note">
    <note>
      Second hand - red, 15000 miles
    </note>
   </vehicle>
   ...
</garage>

I need to get the make of each vehicle from the XML file, and then find the corresponding country from the reference tuple in Python, and store the relevant country so that I can use it again later on.

I realise that I could have just added an extra attribute in the XML file called country, but the XML structure that we now use is well established.


Help would be greatly appreciated,


Thanks,
John
Avatar of ramrom
ramrom
Flag of United States of America image

Your question is a bit vague, and seems to have 3 parts. Help us by selecting from this list of questions, and also tell us where you are stuck on each. Or are you very new to Python?

1 - how do I get the make from tthe XML?

2 - how do I look it up in a tuple of tuples?

3 - how do I store it for later use? (What is your definition of later - during this program execution, or running another program later)?

Why are you storing the factoryloc in tuples? A dictionary would be a lot easier to use.
ASKER CERTIFIED SOLUTION
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial