see whatever…

jump to menu

April 12, 2006

Using the same data in Python and Jython

Filed under: Jython,Programming,Python,RelaxNG — see @ 9:26 pm

I had the problem of needing the same data for some related tasks for which I wrote

  1. a (C)Python script because I used the really great Lingfo – a library to read Excel data with Python together with this Cookbook recipe
  2. a Jython script as I used Jing to validate some XML files with a RelaxNG schema

I may have used other libs which may be available for only one taste of P/J-ython but found these the easiest to use and actually used them for other stuff before so did know how to use them. I could have used Pythons’s lxml but do not know if it validates with the RNC compact syntax or could have used something like Java’s POI to read the Excel but I actually try to minimize the Jython usage as I almost always prefer Python (being faster, 2.4. being much more convenient than Jython’s 2.1 implementation [2.2. still being alpha] etc etc)…

Aynway, so I read data from an Excel sheet with the Python script, read some XML files with the obtained data but needed the same data to do the validation of the XML files with Jython. The XML files themselves are on disk so no problem, the data on the other hand was a bit more complex list of dicts with quite a few information atoms.The solution turned out to be quite simple actually. As for the problem at hand I am able to start both scripts independently (or maybe writing a third shell script which calls both) I put a simple pickle in the Python script and read the same data with pickle in Jython.

Maybe a bit too trivial to actually blog about at all but as I never needed anything like the pickle (shelve, marshall etc) modules and never really saw a use case for them it was actually quite enlightening. I was wondering for some time now how to best integrate Python and Jythons tasks into the same app and this seems like a possibility at least for some cases. And I tried out another module of the very nice and comprehensive stdlib. (Which I missed by the way while doing some other work in PHP ;)

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress