So if you thought that python was good, well jython is even better! You have all the great stuff that you have in java with out the need of programing in java
For example, the other day i was in need of reading some xmls from a web. In python you have httplib for doing HTTP GETs and retrieve the documents and you have nice libraries like Beautiful Soup or pyxml. But in this case i needed something even simpler, as i could use the xsd for this xmls, something like xmlbeans would be great.
I already had the code for downloading the xmls in python, it was something like this,
import httplib, os
def get_listing(conn):
conn.request("GET", "/oai2?verb=ListIdentifiers&metadataPrefix=oai_dc")
response = conn.getresponse()
def get_papers(out):
conn = httplib.HTTPConnection("export.arxiv.org")
listids = get_listing(conn)
for id in listids:
That URL (export.arxiv.org/oai2?verb=ListIdentifiers&metadataPrefix=oai_dc) returns a xml defined by a xsd, so with the help of xmlbean we can generate a jar to handle that xml. The code looks just like a python script and will probably run fine….. Now we can get those identifiers just with the following modifications,
import httplib, os
import org.openarchives.oai.x20
import org.apache.xmlbeans
def get_listing(conn):
conn.request("GET", "/oai2?verb=ListIdentifiers&metadataPrefix=oai_dc")
response = conn.getresponse()
listidsdoc = org.openarchives.oai.x20.OAIPMHDocument.Factory.parse(response.read())
listids = listidsdoc.getOAIPMH().getListIdentifiers().getHeaderArray()
return listids
def get_papers(out):
conn = httplib.HTTPConnection("export.arxiv.org")
listids = get_listing(conn)
for id in listids:
So, the only thing left was the export of the classpath (something like “export CLASSPATH=”"/path/to/xmlbean/jar”") and adding some additional logic to the script to actually do what i was looking for
and my jython hello world was ready
That was a great time with jython and you can have it to, go and download it from here. They have a really painless “next, next, next” installation wizard. You can read something else, here, here and here.