background preloader

Python

Facebook Twitter

Python-spidermonkey - A bridge between Python and the Mozilla SpiderMonkey JavaScript engine. This Python module allows for the implementation of Javascript?

python-spidermonkey - A bridge between Python and the Mozilla SpiderMonkey JavaScript engine.

Classes, objects and functions in Python, as well as the evaluation and calling of Javascript scripts and functions. It borrows heavily from Claes Jacobssen's Javascript Perl module, which in turn is based on Mozilla's PerlConnect Perl binding. This code was originally written by John J. Lee in 2003. After being unmaintained for a number of years, it was subsequently picked up by Atul Varma in 2008.

The first thing you'll want to do is create a Runtime instance, which encapsulates a JSRuntime object from Spidermonkey. A JSRuntime, or runtime, is the space in which the Javascript variables, objects, scripts, and contexts used by your application are allocated. Creating the Runtime instance is straightforward: >>> from spidermonkey import Runtime>>> rt = Runtime() You'll then want to use the Runtime to create a Contextinstance, which encapsulates a JSContext object from Spidermonkey.

>>> cx = rt.new_context() python test.py. Why can't Python find shared objects that are in directories in sys.path. Processing. First programs in PyQt4 toolkit. HomeContents In this part of the PyQt4 tutorial we will learn some basic functionality.

First programs in PyQt4 toolkit

Simple example This is a simple example showing a small window. Yet we can do a lot with this window. We can resize it, maximize it or minimize it. . #! The above code shows a small window on the screen. import sys from PyQt4 import QtGui Here we provide the necessary imports. App = QtGui.QApplication(sys.argv) Every PyQt4 application must create an application object. W = QtGui.QWidget() The QtGui.QWidget widget is the base class of all user interface objects in PyQt4. W.resize(250, 150) The resize() method resizes the widget. W.move(300, 300) The move() method moves the widget to a position on the screen at x=300, y=300 coordinates. w.setWindowTitle('Simple') Here we set the title for our window.

W.show() The show() method displays the widget on the screen. Sys.exit(app.exec_()) Finally, we enter the mainloop of the application. The exec_() method has an underscore. Figure: Simple An application icon #! Figure: Icon. Dynamic Web content and forms processing in Python. Most Web pages are static: the same content appears each time you visit that URL.

Dynamic Web content and forms processing in Python

To put up static content, you simply place a file in or under a specific directory, and give it a name that ends in “.html”. If your page is hosted at the New Mexico Tech Computer Center (TCC), static pages must reside in subdirectory “public_html” under your home directory. This document describes technique for dynamic web pages: their content is generated on demand. This technique is called CGI, for Common Gateway Interface. Instead of writing the page's content, you will write a program that generates the content as its output. One of the commonest uses for dynamic web pages is to handle forms. However, dynamic web pages are useful for other applications besides forms handling.