Advanced exec and eval

Imagine easily sending code to update changes to a program or easily moving code around the network to update remote clients. How about adding scriptability so that end users can write scripts to automate common tasks? In other languages, these things are hard to accomplish. In Python they're built into the language.

compile()

The compile(string, filename, kind) function converts a string into a code object that represents Python bytecode. The filename argument states the origin of the code, that is, the file name; the kind argument specifies how the code should be compiled based on the contents of the string argument. There are three choices for kind:

  • exec— a group of statements

  • eval— a single expression

  • single— a single ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.