View Single Post
Old Aug 17th, 2007, 3:31 AM   #7
Primusville
Newbie
 
Join Date: Aug 2007
Posts: 11
Rep Power: 0 Primusville is on a distinguished road
Quote:
Originally Posted by Game_Ender View Post
You don't really have to use XML. You just need a structured data format you could use Json with the Python
simplejson library.

Here is a usage example:
python Syntax (Toggle Plain Text)
  1. import simplejson
  2.  
  3. # file mycards.txt
  4. # {
  5. # "Blue Eyes White Dragon" : {
  6. # "hitpoints" : 1202020
  7. # "attacks" : ["Fire Spin", "Tail Whip"]
  8. # }
  9. # }
  10.  
  11. mycards = file("mycards.txt")
  12. myData = simplejson.load(mycards.read())
  13. hitpoints = myData["Blue Eyes White Dragon"]["hitpoints"]

XML might be a good data interchange format, but its pretty verbose, and a pain to work with by hand compared to Json and Yaml. The key is, there is no "parsing" with Json or Yaml. They are already in dict + list format. The data structure in the file exactly maps to python. No hoop jumping or awkward APIs.
Thank you! That's just what I was looking for. At first XML seemed like a great idea, but then I realized the unnecessary difficulty of parsing it in Python. Thanks again for the help; now I think that I can finally get to work on my game.

Edit: I installed simplejson, and it's completely PERFECT for what I need. It works just as well as I hoped it would. Thanks once again for your assistance.

Last edited by Primusville; Aug 17th, 2007 at 4:24 AM.
Primusville is offline   Reply With Quote