views:

23

answers:

1

I have some MySQL database server information that needs to be shared between a Python backend and a PHP frontend.

What is the best way to go about storing the information in a manner wherein it can be read easily by Python and PHP?

I can always brute force it with a bunch of str.replace() calls in Python and hope it works if nobody has a solution, or I can just maintain two separate files, but it would be a bunch easier if I could do this automatically.

I assume it would be easiest to store the variables in PHP format directly and do conversions in Python, and I know there exist Python modules for serializing and unserializing PHP, but I haven't been able to get it all figured out.

Any help is appreciated!

+3  A: 

Store the shared configuration in a plain text file, preferably in a standard format.

You might consider yaml, ini, or json.

I'm pretty sure both PHP and python can very trivially read and parse all three of those formats.

timdev
If it's a simple set of variables without a complex data structure (like a mysql connection descriptor would be), ini seems the most straightforward of the 3.
Mike Sherov
@Mike Sherov - That's what I'd probably do
timdev