Package org.bytedeco.embeddedpython
Class Python
- java.lang.Object
-
- org.bytedeco.embeddedpython.Python
-
public class Python extends Object
Python interpreter.If you embed two Python interpreters, many Python libraries do not work correctly. Therefore this class is a singleton class. All the methods are static.
This class is thread-safe. All the methods are synchronized.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> T
eval(String src)
Python built-in eval().static void
exec(String src)
Python built-in exec().static <T> T
get(String name)
Get the global Python variable and convert it to a Java object.static void
put(String name, Object value)
Convert the Java object and set it to the global Python variable.
-
-
-
Method Detail
-
eval
public static <T> T eval(String src)
Python built-in eval().- Type Parameters:
T
- The Java class after conversion from Python.- Parameters:
src
- Python code. This must be a single line code.- Returns:
- The Java object converted from the Python object.
-
exec
public static void exec(String src)
Python built-in exec().- Parameters:
src
- Python code. This can be multiple lines code.
-
get
public static <T> T get(String name)
Get the global Python variable and convert it to a Java object.Type mappings. Python to Java. Python Java None null bool boolean int long float double str String scalar np.bool8 boolean scalar np.int8 byte scalar np.int16 short scalar np.uint16 char scalar np.int32 int scalar np.int64 long scalar np.float32 float scalar np.float64 double scalar np.datetime64[W, D, h, m, s, ms, us, or ns] Instant bytes byte[] bytearray byte[] dict LinkedHashMap ndarray np.bool8 NpNdarrayBoolean ndarray np.int8 NpNdarrayByte ndarray np.int16 NpNdarrayShort ndarray np.uint16 NpNdarrayChar ndarray np.int32 NpNdarrayInt ndarray np.int64 NpNdarrayLong ndarray np.float32 NpNdarrayFloat ndarray np.float64 NpNdarrayDouble ndarray np.datetime64[W, D, h, m, s, ms, us, or ns] NpNdarrayInstant iterable ArrayList - Type Parameters:
T
- The Java class after conversion from Python.- Parameters:
name
- The variable name- Returns:
- The Java object converted from the Python object.
- Throws:
PythonException
- If the value cannot convert to a Java object.NoSuchElementException
- If the variable does not exists.
-
put
public static void put(String name, Object value)
Convert the Java object and set it to the global Python variable.Type mappings. Java to Python. Java Python null None boolean bool byte int short int char int int int long int float float double float Instant np.datetime64[ns] String str byte[] bytes boolean[] np.ndarray, dtype=np.bool8 short[] np.ndarray, dtype=np.int16 char[] np.ndarray, dtype=np.uint16 int[] np.ndarray, dtype=np.int32 long[] np.ndarray, dtype=np.int64 float[] np.ndarray, dtype=np.float32 double[] np.ndarray, dtype=np.float64 Instant[] np.ndarray, dtype=np.datetime64[ns] NpNdarrayBoolean np.ndarray, dtype=np.bool8 NpNdarrayByte np.ndarray, dtype=np.int8 NpNdarrayShort np.ndarray, dtype=np.int16 NpNdarrayChar np.ndarray, dtype=np.uint16 NpNdarrayInt np.ndarray, dtype=np.int32 NpNdarrayLong np.ndarray, dtype=np.int64 NpNdarrayFloat np.ndarray, dtype=np.float32 NpNdarrayDouble np.ndarray, dtype=np.float64 NpNdarrayInstant np.ndarray, dtype=np.datetime64[ns] java.util.Map dict scala.collection.Map dict Object[] list Iterable list scala.Function0 - Function22 built-in global Python function - Parameters:
name
- The variable namevalue
- The value to put.- Throws:
PythonException
- If the value cannot convert to a Python object.
-
-