PHP calling Python

For no reason at all, I decided to make Python a first class scripting language in the Data Warehouse. It turned out to be very simple it took about six hours to implement the Python support, most of the time spent on reading and deciding how to design the Python interface. I have no previous knowledge of Python so it took a while to get going. And I did as I use to, Google and trial & error until it worked. What I have up and running now needs some polishing and fine tuning, but it works pretty well.

This schedule consists of two jobs, the first one calling Python Code, the second ‘getPythonTags’ job picks up two job references created by the first ‘testPython’ job. Normally a script job creates output in the job map e.g. graphic images, but they may create symbolics like the @testPython.FNAME and  @testPython.LNAME for use in subsequent jobs.
Implementing Python support was done by this code:

The result is stored by the Python code in the PHP array PYTHON_RESULT.

This array consists of RESULT (true) and the job array which carries the symbolics in the _xlate array. Having implemented the Python support I only had to write a Python skeleton program. And here it is.

With the help of the serek package imported at the top of the code it was child’s play to import the important control blocks (PHP arrays) from the Data Warehouse and export the result to the Data Warehouse as a PHP array.

In this hideous display you can see how the SQL query  
select '@testPython.FNAME', '@testPython.LNAME'; 
is translated to select 'Kalle', 'Kula';

It was fun to implement the Python support, if it will be used I do not know, we will see. But I will probably implement support for Node.js and Perl6 just for the hell of it. Looking at the watch it took me about ten hours (not six) to do this. Time flies when you have fun.

No comments:

Post a Comment