javascript execution from Python script

Gerhard Häring gerhard.haering at
Mon Aug 26 19:32:28 CEST 2002

* Justin Guerin <jguerin at> [2002-08-26 11:19 -0600]:
> Hello everyone,
> 	Does anyone know if there is a way to execute javascript from within a Python 
> script?

I'm pretty sure there is none. Your best bet is to expose an existing
JavaScript implementation to Python.

> I'm trying to write a script to browse a web site that makes use of 
> javascript rather liberally.
> 	I checked, where Guido 
> wrote that "a Python implementation written in Java is under development, 
> which allows calling Python code from Java and vice versa."  If he's 
> referring to Jython, then maybe I need to check the Jython web site more 
> carefully, but from what I saw, it allows you to run Python code from within 
> Java, but not Java code from within Python.

Jython can call to Java code, too: they're both executed in the same
Virtual Machine.

> And actually, since I'm more interested in javascript, I'm not sure it
> matters, anyway.

It probably doesn't. The only connection is that many browsers have
techniques to script Java applets via JavaScript. Sometimes, it also
works the other way round, I hear. So you could _perhaps_ write a Jython
applet that has access to the JavaScript engine in the same browser. If
I were a project manager, I'd say RISK FACTOR: HIGH.

> (I'm afraid I'm quite unfamiliar with Java and javascript.)

"Java is not JavaScript", that's even the subtitle of the FAQ ;-) All they share are the first four letters.

mail:   gerhard <at> bigfoot <dot> de       registered Linux user #64239
web:    OpenPGP public key id AD24C930
public key fingerprint: 3FCC 8700 3012 0A9E B0C9  3667 814B 9CAA AD24 C930
reduce(lambda x,y:x+y,map(lambda x:chr(ord(x)^42),tuple('zS^BED\nX_FOY\x0b')))

More information about the Python-list mailing list