[Tutor] Parsing problem
Liam Clarke
cyresse at gmail.com
Mon Jul 18 13:24:16 CEST 2005
Hi all,
I am a Europa Universalis II freak, and in attempting to recreate a lost
saved game, I had to delve into the mechanics of the save game file.
Which, luckily, is plain text.
It's formatted like this -
country = {
tag = ENG
ai = {
flags = { }
combat = { DAU FRA ORL PRO }
continent = { }
area = { }
region = { "British Isles" "NorthSeaSea" "ECAtlanticSea" "NAtlanticSea"
"TagoSea" "WCAtlanticSea" }
war = 60
ferocity = no
}
}
Now, it tends to conform to certain rules, which make it a bit easier,
there's always a space either side of an equals sign and such forth, which
should hopefully make parsing stuff like -
date = { year = 1421 month = july day = 7 }
a bit less complex, considering that it uses space to separate list items.
What I need to do, is to turn this into a data structure, and I think this
relates to XML in a way. Basically, I want to parse the above (I assume I'll
be counting braces to find where I am) so that a country object called ENG
has a dictionary called ai, which points to lists, integers, strings etc.
and so forth.
If anyone has any links to any (simple) examples of XML parsing or similar
which could give me pointers as to how to go about this, it'd be much
appreciated.
Regards,
Liam Clarke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050718/72dc77bb/attachment.htm
More information about the Tutor
mailing list