HTTPS clone URL

Subversion checkout URL

Examples

Pages 2

Clone this wiki locally

The behavior of PyCow can be seen at best on some examples.

Note: PyCow currently removes any comments in the code.

Namespaces

PyCow can wrap your Python module in a namespace (commandline: pycow.py -n namespace inputfile.py).
If you do that, PyCow will look for a optional `all` variable in your module and make only the specified
classes/functions publicly accessible.

Classes, subclasses and functions

I have ported some of MooTools’ functionality to Python in order to keep semantics clean
between the two languages. This introduces the “Class” decorator, which fixes an issue
and adds the “implements” method to the class. Note that class decorators are supported
in Python 2.6 and later only, please upgrade your installation if neccessary.

The “Implements” decorator

There is another feature in MooTools besides the Extends property of classes: The Implements property.

From the MooTools documentation:

Implements is similar to Extends, except that it overrides properties without inheritance. Useful when
implementing a default set of properties in multiple Classes.

This is often used in conjunction with the “Options” and “Events” utility classes of MooTools. I have
ported them to Python for your convenience. The following example also explains what is fixed by the
“Class” decorator.

While statement

i = 0
while i < 3 and not False: # While statement
print i
i += 2 # Assignment operator
i += 1 # special case

Resulting JavaScript:

var i = 0;
while (i < 3 && !false) {
dbgprint(i);
i += 2;
i++;
}

For statement

The “for” statement is a special case in Python. There is always a list (or generator) which is
iterated; this behaviour is just like the “foreach” statement in other languages. Because of that,
and some other side effects, Python “for” statements cannot be directly converted to JavaScript
“for” statements. PyCow solves this by using Java-Style iterators which come with the PyCow
runtime script.