Name
set
Synopsis
voidinterp.set(Stringname,PyObjectvalue) voidinterp.set(Stringname,Objectvalue)
Binds the attribute named name in
interp’s namespace to
value. The second overload also converts
the value to a PyObject.
The org.python.core
package supplies a class __builtin__ whose
static methods let your Java code access the functionality of Python
built-in functions. The compile method, in
particular, is quite similar to Python built-in function
compile, covered in Chapter 8 and Chapter 13. Your Java
code can call compile with three
String arguments (a string of source code, a
filename to use in error messages, and a
kind that is normally
"exec“), and compile returns a
PyObject instance p
that is a precompiled Python bytecode object. You can repeatedly call
interp
.exec(
p
)
to execute the Python statements in p
without the overhead of compiling the Python source for each
execution. The advantages are the same as covered in Chapter 13.
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