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.
Get Python in a Nutshell 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.