One of the first changes I made this week to PythonScript was to change the default variable scope from global to local. PythonScript now follows the Python standard, where each function defines a new scope of local variables. The global keyword is now used to declare global variables when you need to assign a value to a global. The commit to do this is tiny, it simply injects var for you by looking at all variable assignments in a function.
I also added and improved some builtins: min, max, abs, chr, ord, tuple and dict. The new dict goes beyond what is possible in normal Python by allowing any type to be used as a key, so in case you ever had wanted to use a list or another dict as a dict key, now you can in PythonScript. See my commits here: , , 
<html> <head> <script src="pythonscript.js"></script> </head> <body> <button id="mybutton" onclick="test()">click me</button> <script type="text/python"> a = 'hello' b = 'world' def test(): con = document.createElement( 'div' ) con.setAttribute('id', 'mydiv') document.body.appendChild(con) print( con ) txt = document.createTextNode( a+b ) con.appendChild(txt) print( con.getAttribute('id') ) btn = document.getElementById('mybutton') print(btn) btn.firstChild.nodeValue = 'CLICKED!' </script> </body> </html>
create a 32bit floating point array
arr = array('f', [0.1, 0.2] ) arr.append( 1.1 ) arr.append( 2.2 ) for value in arr: print( value )
create a 16bit floating point array
arr = array('float16', [-10.0, 3.141592653589793, 10.0]) print 'error:', arr - 3.141592653589793
Above creates a special quantized array type. The DataView API has no notion of '16bit floats', but we can roll our own using Int16. Internally the array class finds the min and max the array will hold by looking at the array used to initialize it, then when packing and adding new values they are scaled and quantized. Later when accessing the elements of the array they get 'unscaled and unquantized' back into floats. The error between input and output is minimal for an array with minimal dynamic range. The example above has a dynamic range of -10 to 10, the error for PI is only 0.0000172, not bad. 
create an 8bit floating point array
arr = array('float8', [-10.0, 3.141592653589793, 10.0]) print 'error:', arr - 3.141592653589793
For the ultimate memory savings you can use the special 8bit float type that only uses one byte per-number. This can be used for cases where a larger amount of error is acceptable, and the input data has values that are not far apart (low dynamic range). The above example, with the same dynamic range as the previous example produces a greater error of about 0.07. If the dynamic range is increased to -50 to 50, then the error increases to 0.38568 and PI becomes 2.7559.