Using Python instead of XML for loading resources in C++?
Question: I am building a simple 2D game (for learning purposes) in c++ and am currently
parsing XML files using TinyXML to load my textures and other resources.
Recently, however, I have been intrigued by python and wish to use python
instead of XML for various reasons(once again, for learning purposes).

I was wondering if I could translate my objects in XML into a large tuple in
python, and then by using an embedded python interpreter parse the elements of
the tuple and extract the data into my C++ game.

Mount and Blade Warband (A game that first introduced me to Python modules)
seems to do it this way, and has sparked my interest.

Here is an example of the first two elements in a large tuple for Mount and
Blade....

    
    
    sounds = [
    
     ("click", sf_2d|sf_vol_3,["drum_3.ogg"]),
    
     ("tutorial_1", sf_2d|sf_vol_7,["tutorial_1.ogg"]),
    

However, Mount and Blade requires you run an executable on these python
scripts which translates them into large .txt files...

    
    
    drum_3.ogg 769
    tutorial_1.ogg 1793
    

Which leads me to believe that the game is actually parsing these text files.

Is what I attempt to do still possible?

I have searched around for some APIs and have found a few good ones,
predominately Python/C or Boost.Python and was hoping someone may be able to
give me some direction.

Thank you very much and any input is greatly appreciated!


Answer: Resource/settings files written in python are suitable if your engine (the
game or some special resource processor) is written in python.

This is because you can just `import <resource-file>` from your pythonic
module, in place of parsing on XML/text/other-format.

If you have no python involved, I can't see any reason to write resources in
python.

Regarding your example about Mount and Blade - exactly as I've said, when game
is not written in python, you should use some resource pre-processor.

