Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython
by Richard Hightower
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access