Class Py


public final class Py extends PrePy
  • Field Details

    • None

      public static final PyObject None
      The singleton None Python object
    • Ellipsis

      public static final PyObject Ellipsis
      The singleton Ellipsis Python object - written as ... when indexing
    • NotImplemented

      public static final PyObject NotImplemented
      The singleton NotImplemented Python object. Used in rich comparison
    • NoKeywords

      public static final String[] NoKeywords
      A zero-length array of Strings to pass to functions that don't have any keyword arguments
    • EmptyObjects

      public static final PyObject[] EmptyObjects
      A zero-length array of PyObject's to pass to functions when we have no arguments
    • EmptyFrozenSet

      public static final PyFrozenSet EmptyFrozenSet
      A frozenset with zero elements
    • EmptyTuple

      public static final PyTuple EmptyTuple
      A tuple with zero elements
    • Zero

      public static final PyInteger Zero
      The Python integer 0
    • One

      public static final PyInteger One
      The Python integer 1
    • False

      public static final PyBoolean False
      The Python boolean False
    • True

      public static final PyBoolean True
      The Python boolean True
    • EmptyString

      public static final PyString EmptyString
      A zero-length Python byte string
    • EmptyUnicode

      public static final PyUnicode EmptyUnicode
      A zero-length Python Unicode string
    • Newline

      public static final PyString Newline
      A Python string containing '\n'
    • UnicodeNewline

      public static final PyUnicode UnicodeNewline
      A Python unicode string containing '\n'
    • Space

      public static final PyString Space
      A Python string containing ' '
    • UnicodeSpace

      public static final PyUnicode UnicodeSpace
      A Python unicode string containing ' '
    • TPFLAGS_HEAPTYPE

      public static final long TPFLAGS_HEAPTYPE
      Set if the type object is dynamically allocated
      See Also:
    • TPFLAGS_BASETYPE

      public static final long TPFLAGS_BASETYPE
      Set if the type allows subclassing
      See Also:
    • TPFLAGS_IS_ABSTRACT

      public static final long TPFLAGS_IS_ABSTRACT
      Type is abstract and cannot be instantiated
      See Also:
    • NoConversion

      public static final Object NoConversion
      A unique object to indicate no conversion is possible in __tojava__ methods
    • OSError

      public static PyObject OSError
    • NotImplementedError

      public static PyObject NotImplementedError
    • EnvironmentError

      public static PyObject EnvironmentError
    • OverflowError

      public static PyObject OverflowError
    • RuntimeError

      public static PyObject RuntimeError
    • KeyboardInterrupt

      public static PyObject KeyboardInterrupt
    • FloatingPointError

      public static PyObject FloatingPointError
    • SyntaxError

      public static PyObject SyntaxError
    • IndentationError

      public static PyObject IndentationError
    • TabError

      public static PyObject TabError
    • AttributeError

      public static PyObject AttributeError
    • IOError

      public static PyObject IOError
    • KeyError

      public static PyObject KeyError
    • AssertionError

      public static PyObject AssertionError
    • TypeError

      public static PyObject TypeError
    • ReferenceError

      public static PyObject ReferenceError
    • SystemError

      public static PyObject SystemError
    • IndexError

      public static PyObject IndexError
    • ZeroDivisionError

      public static PyObject ZeroDivisionError
    • NameError

      public static PyObject NameError
    • UnboundLocalError

      public static PyObject UnboundLocalError
    • SystemExit

      public static PyObject SystemExit
    • StopIteration

      public static PyObject StopIteration
    • GeneratorExit

      public static PyObject GeneratorExit
    • ImportError

      public static PyObject ImportError
    • ValueError

      public static PyObject ValueError
    • UnicodeError

      public static PyObject UnicodeError
    • UnicodeTranslateError

      public static PyObject UnicodeTranslateError
    • UnicodeDecodeError

      public static PyObject UnicodeDecodeError
    • UnicodeEncodeError

      public static PyObject UnicodeEncodeError
    • EOFError

      public static PyObject EOFError
    • MemoryError

      public static PyObject MemoryError
    • BufferError

      public static PyObject BufferError
    • ArithmeticError

      public static PyObject ArithmeticError
    • LookupError

      public static PyObject LookupError
    • StandardError

      public static PyObject StandardError
    • Exception

      public static PyObject Exception
    • BaseException

      public static PyObject BaseException
    • Warning

      public static PyObject Warning
    • UserWarning

      public static PyObject UserWarning
    • DeprecationWarning

      public static PyObject DeprecationWarning
    • PendingDeprecationWarning

      public static PyObject PendingDeprecationWarning
    • SyntaxWarning

      public static PyObject SyntaxWarning
    • RuntimeWarning

      public static PyObject RuntimeWarning
    • FutureWarning

      public static PyObject FutureWarning
    • ImportWarning

      public static PyObject ImportWarning
    • UnicodeWarning

      public static PyObject UnicodeWarning
    • BytesWarning

      public static PyObject BytesWarning
    • JavaError

      public static PyObject JavaError
    • defaultSystemState

      public static volatile PySystemState defaultSystemState
    • stderr

      public static StdoutWrapper stderr
  • Method Details

    • OSError

      public static PyException OSError(String message)
    • OSError

      public static PyException OSError(IOException ioe)
    • OSError

      public static PyException OSError(jnr.constants.Constant errno)
    • OSError

      public static PyException OSError(jnr.constants.Constant errno, PyObject filename)
    • NotImplementedError

      public static PyException NotImplementedError(String message)
    • EnvironmentError

      public static PyException EnvironmentError(String message)
    • OverflowError

      public static PyException OverflowError(String message)
    • RuntimeError

      public static PyException RuntimeError(String message)
    • KeyboardInterrupt

      public static PyException KeyboardInterrupt(String message)
    • FloatingPointError

      public static PyException FloatingPointError(String message)
    • SyntaxError

      public static PyException SyntaxError(String message)
    • AttributeError

      public static PyException AttributeError(String message)
    • IOError

      public static PyException IOError(IOException ioe)
    • IOError

      public static PyException IOError(String message)
    • IOError

      public static PyException IOError(jnr.constants.Constant errno)
    • IOError

      public static PyException IOError(jnr.constants.Constant errno, String filename)
    • IOError

      public static PyException IOError(jnr.constants.Constant errno, PyObject filename)
    • KeyError

      public static PyException KeyError(String message)
    • KeyError

      public static PyException KeyError(PyObject key)
    • AssertionError

      public static PyException AssertionError(String message)
    • TypeError

      public static PyException TypeError(String message)
    • ReferenceError

      public static PyException ReferenceError(String message)
    • SystemError

      public static PyException SystemError(String message)
    • IndexError

      public static PyException IndexError(String message)
    • ZeroDivisionError

      public static PyException ZeroDivisionError(String message)
    • NameError

      public static PyException NameError(String message)
    • UnboundLocalError

      public static PyException UnboundLocalError(String message)
    • StopIteration

      public static PyException StopIteration(String message)
    • GeneratorExit

      public static PyException GeneratorExit(String message)
    • ImportError

      public static PyException ImportError(String message)
    • ValueError

      public static PyException ValueError(String message)
    • UnicodeError

      public static PyException UnicodeError(String message)
    • UnicodeTranslateError

      public static PyException UnicodeTranslateError(String object, int start, int end, String reason)
    • UnicodeDecodeError

      public static PyException UnicodeDecodeError(String encoding, String object, int start, int end, String reason)
    • UnicodeEncodeError

      public static PyException UnicodeEncodeError(String encoding, String object, int start, int end, String reason)
    • EOFError

      public static PyException EOFError(String message)
    • memory_error

      public static void memory_error(OutOfMemoryError t)
    • MemoryError

      public static PyException MemoryError(String message)
    • BufferError

      public static PyException BufferError(String message)
    • Warning

      public static void Warning(String message)
    • UserWarning

      public static void UserWarning(String message)
    • DeprecationWarning

      public static void DeprecationWarning(String message)
    • PendingDeprecationWarning

      public static void PendingDeprecationWarning(String message)
    • SyntaxWarning

      public static void SyntaxWarning(String message)
    • RuntimeWarning

      public static void RuntimeWarning(String message)
    • FutureWarning

      public static void FutureWarning(String message)
    • ImportWarning

      public static void ImportWarning(String message)
    • UnicodeWarning

      public static void UnicodeWarning(String message)
    • BytesWarning

      public static void BytesWarning(String message)
    • warnPy3k

      public static void warnPy3k(String message)
    • warnPy3k

      public static void warnPy3k(String message, int stacklevel)
    • warning

      public static void warning(PyObject category, String message)
    • warning

      public static void warning(PyObject category, String message, int stacklevel)
    • warning

      public static void warning(PyObject category, String message, String filename, int lineno, String module, PyObject registry)
    • JavaError

      public static PyException JavaError(Throwable t)
    • tojava

      public static <T> T tojava(PyObject o, Class<T> c)
      Convert a given PyObject to an instance of a Java class. Identical to o.__tojava__(c) except that it will raise a TypeError if the conversion fails.
      Parameters:
      o - the PyObject to convert.
      c - the class to convert it to.
    • tojava

      public static Object tojava(PyObject o, String s)
    • newInteger

      public static final PyInteger newInteger(int i)
    • newInteger

      public static PyObject newInteger(long i)
    • newLong

      public static PyLong newLong(String s)
    • newLong

      public static PyLong newLong(BigInteger i)
    • newLong

      public static PyLong newLong(int i)
    • newLong

      public static PyLong newLong(long l)
    • newImaginary

      public static PyComplex newImaginary(double v)
    • newFloat

      public static PyFloat newFloat(float v)
    • newFloat

      public static PyFloat newFloat(double v)
    • newString

      public static PyString newString(char c)
    • newString

      public static PyString newString(String s)
      Create a PyString from a Java String. Thethe character codes must all be all < 256. (This is checked.)
      Parameters:
      s - character codes are all < 256.
      Returns:
      a new PyString
    • newStringOrUnicode

      public static PyString newStringOrUnicode(String s)
      Return a PyString for the given Java String, if it can be represented as US-ASCII, and a PyUnicode otherwise.
      Parameters:
      s - string content
      Returns:
      PyString or PyUnicode according to content of s.
    • newStringOrUnicode

      public static PyString newStringOrUnicode(PyObject precedent, String s)
      Return a PyString for the given Java String, if it can be represented as US-ASCII and if a preceding object is not a PyUnicode, and a PyUnicode otherwise. In some contexts, we want the result to be a PyUnicode if some preceding result is a PyUnicode.
      Parameters:
      precedent - string of which the type sets a precedent
      s - string content
      Returns:
      PyString or PyUnicode according to content of s.
    • newStringUTF8

      public static PyString newStringUTF8(String s)
    • fileSystemDecode

      public static String fileSystemDecode(PyString filename)
      Return a file name or path as Unicode (Java UTF-16 String), decoded if necessary from a Python bytes object, using the file system encoding. In Jython, this encoding is UTF-8, irrespective of the OS platform. This method is comparable with Python 3 os.fsdecode, but for Java use, in places such as the os module. If the argument is not a PyUnicode, it will be decoded using the nominal Jython file system encoding. If the argument is a PyUnicode, its String is returned.
      Parameters:
      filename - as bytes to decode, or already as unicode
      Returns:
      unicode version of path
    • fileSystemDecode

      public static String fileSystemDecode(PyObject filename)
      As fileSystemDecode(PyString) but raising ValueError if not a str or unicode.
      Parameters:
      filename - as bytes to decode, or already as unicode
      Returns:
      unicode version of the file name
    • fileSystemEncode

      public static PyString fileSystemEncode(String filename)
      Return a PyString object we can use as a file name or file path in places where Python expects a bytes (that is a str) object in the file system encoding. In Jython, this encoding is UTF-8, irrespective of the OS platform.

      This is subtly different from CPython's use of "file system encoding", which tracks the platform's choice so that OS services may be called that have a bytes interface. Jython's interaction with the OS occurs via Java using String arguments representing Unicode values, so we have no need to match the encoding actually chosen by the platform (e.g. 'mbcs' on Windows). Rather we need a nominal Jython file system encoding, for use where the standard library forces byte paths on us (in Python 2). There is no reason for this choice to vary with OS platform. Methods receiving paths as bytes will fileSystemDecode(PyString) them again for Java.

      Parameters:
      filename - as unicode to encode, or already as bytes
      Returns:
      encoded bytes version of path
    • fileSystemEncode

      public static PyString fileSystemEncode(PyString filename)
      Return a PyString object we can use as a file name or file path in places where Python expects a bytes (that is, str) object in the file system encoding. In Jython, this encoding is UTF-8, irrespective of the OS platform. This method is comparable with Python 3 os.fsencode. If the argument is a PyString, it is returned unchanged. If the argument is a PyUnicode, it is converted to a bytes using the nominal Jython file system encoding.
      Parameters:
      filename - as unicode to encode, or already as bytes
      Returns:
      encoded bytes version of path
    • getenv

      public static PyString getenv(PyString name)
      The same as getenv(name, null). See getenv(PyString, PyString).
    • getenv

      public static PyString getenv(PyString name, PyString defaultValue)
      Get the value of the environment variable named from os.environ or return the given default value. Empty string values are treated as undefined for this purpose.
      Parameters:
      name - of the environment variable.
      defaultValue - to return if key is not defined (may be null.
      Returns:
      the corresponding value or defaultValue.
    • getenv

      public static String getenv(String name)
      The same as getenv(name, null). See getenv(String, String).
    • getenv

      public static String getenv(String name, String defaultValue)
      Get the value of the environment variable named from os.environ or return the given default value. This is a convenience wrapper on getenv(PyString, PyString) which takes care of the fact that environment variables are FS-encoded.
      Parameters:
      name - to access in the environment.
      defaultValue - to return if key is not defined.
      Returns:
      the corresponding value or defaultValue.
    • newStringMap

      public static PyStringMap newStringMap()
    • newUnicode

      public static PyUnicode newUnicode(char c)
    • newUnicode

      public static PyUnicode newUnicode(String s)
    • newUnicode

      public static PyUnicode newUnicode(String s, boolean isBasic)
    • newBoolean

      public static PyBoolean newBoolean(boolean t)
    • newDate

      public static PyObject newDate(Date date)
    • newTime

      public static PyObject newTime(Time time)
    • newDatetime

      public static PyObject newDatetime(Timestamp timestamp)
    • newDecimal

      public static PyObject newDecimal(String decimal)
    • newCode

      public static PyCode newCode(int argcount, String[] varnames, String filename, String name, boolean args, boolean keywords, PyFunctionTable funcs, int func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags)
    • newCode

      public static PyCode newCode(int argcount, String[] varnames, String filename, String name, int firstlineno, boolean args, boolean keywords, PyFunctionTable funcs, int func_id, String[] cellvars, String[] freevars, int npurecell, int moreflags)
    • newCode

      public static PyCode newCode(int argcount, String[] varnames, String filename, String name, boolean args, boolean keywords, PyFunctionTable funcs, int func_id)
    • newCode

      public static PyCode newCode(int argcount, String[] varnames, String filename, String name, int firstlineno, boolean args, boolean keywords, PyFunctionTable funcs, int func_id)
    • newJavaCode

      public static PyCode newJavaCode(Class<?> cls, String name)
    • newJavaFunc

      public static PyObject newJavaFunc(Class<?> cls, String name)
    • initPython

      public static boolean initPython()
    • findClass

      public static Class<?> findClass(String name)
      Find and load a Java class by name.
      Parameters:
      name - of the Java class.
      Returns:
      the class, or null if it wasn't found or something went wrong
    • findClassEx

      public static Class<?> findClassEx(String name, String reason) throws PyException
      Find and load a Java class by name.
      Parameters:
      name - Name of the Java class.
      reason - for finding the class. Used in debugging messages.
      Returns:
      the class, or null if it simply wasn't found
      Throws:
      PyException - JavaError wrapping errors occurring when the class is found but cannot be loaded.
    • initProxy

      public static void initProxy(PyProxy proxy, String module, String pyclass, Object[] args)
    • runMain

      public static void runMain(PyRunnable main, String[] args) throws Exception
      Initializes a default PythonInterpreter and runs the code from PyRunnable.getMain() as __main__ Called by the code generated in Module.addMain()
      Throws:
      Exception
    • runMain

      public static void runMain(CodeBootstrap main, String[] args) throws Exception
      Initializes a default PythonInterpreter and runs the code loaded from the CodeBootstrap as __main__ Called by the code generated in Module.addMain()
      Throws:
      Exception
    • printException

      public static void printException(Throwable t)
      Display an exception and stack trace through printException(Throwable, PyFrame, PyObject).
      Parameters:
      t - to display
    • printException

      public static void printException(Throwable t, PyFrame f)
      Display an exception and stack trace through printException(Throwable, PyFrame, PyObject).
      Parameters:
      t - to display
      f - frame at which to start the stack trace
    • printException

      public static void printException(Throwable t, PyFrame f, PyObject file)
      Display an exception and stack trace. If the exception was SystemExit and Options.inspect==false, this will exit the JVM.
      Parameters:
      t - to display
      f - frame at which to start the stack trace
      file - output onto this stream or stderr if null
    • displayException

      public static void displayException(PyObject type, PyObject value, PyObject tb, PyObject file)
      Print the description of an exception as a big string. The arguments are closely equivalent to the tuple returned by Python sys.exc_info, on standard error or a given byte-oriented file. Compare with Python traceback.print_exception.
      Parameters:
      type - of exception
      value - the exception parameter (second argument to raise)
      tb - traceback of the call stack where the exception originally occurred
      file - to print encoded string to, or null meaning standard error
    • formatException

      public static String formatException(PyObject type, PyObject value)
    • formatException

      public static String formatException(PyObject type, PyObject value, boolean useRepr)
    • writeUnraisable

      public static void writeUnraisable(Throwable unraisable, PyObject obj)
    • assert_

      public static void assert_(PyObject test, PyObject message)
    • assert_

      public static void assert_(PyObject test)
    • addTraceback

      public static void addTraceback(Throwable t, PyFrame frame)
    • setException

      public static PyException setException(Throwable t, PyFrame frame)
    • matchException

      @Deprecated public static boolean matchException(PyException pye, PyObject exc)
      Deprecated.
      As of Jython 2.5, use PyException.match(org.python.core.PyObject) instead.
    • makeException

      public static PyException makeException(PyObject type, PyObject value, PyObject traceback)
    • makeException

      public static PyException makeException(PyObject type, PyObject value)
    • makeException

      public static PyException makeException(PyObject type)
    • makeException

      public static PyException makeException()
    • runCode

      public static PyObject runCode(PyCode code, PyObject locals, PyObject globals)
    • exec

      public static void exec(PyObject o, PyObject globals, PyObject locals)
    • getThreadState

      public static final ThreadState getThreadState()
    • getThreadState

      public static final ThreadState getThreadState(PySystemState newSystemState)
    • setSystemState

      public static final PySystemState setSystemState(PySystemState newSystemState)
    • getSystemState

      public static final PySystemState getSystemState()
    • getFrame

      public static PyFrame getFrame()
    • setFrame

      public static void setFrame(PyFrame f)
    • getConsole

      public static Console getConsole()
      Get the Jython Console (used for input(), raw_input(), etc.) as constructed and set by PySystemState initialization.
      Returns:
      the Jython Console
    • installConsole

      public static void installConsole(Console console) throws UnsupportedOperationException, IOException
      Install the provided Console, first uninstalling any current one. The Jython Console is used for raw_input() etc., and may provide line-editing and history recall at the prompt. A Console may replace System.in with its line-editing input method.
      Parameters:
      console - The new Console object
      Throws:
      UnsupportedOperationException - if some prior Console refuses to uninstall
      IOException - if Console.install() raises it
    • importSiteIfSelected

      public static boolean importSiteIfSelected()
    • print

      public static void print(PyObject file, PyObject o)
    • printComma

      public static void printComma(PyObject file, PyObject o)
    • println

      public static void println(PyObject file, PyObject o)
    • printlnv

      public static void printlnv(PyObject file)
    • print

      public static void print(PyObject o)
    • printComma

      public static void printComma(PyObject o)
    • println

      public static void println(PyObject o)
    • println

      public static void println()
    • flushLine

      public static void flushLine()
    • py2boolean

      public static boolean py2boolean(PyObject o)
    • py2byte

      public static byte py2byte(PyObject o)
    • py2short

      public static short py2short(PyObject o)
    • py2int

      public static int py2int(PyObject o)
    • py2int

      public static int py2int(PyObject o, String msg)
    • py2long

      public static long py2long(PyObject o)
    • py2float

      public static float py2float(PyObject o)
    • py2double

      public static double py2double(PyObject o)
    • py2char

      public static char py2char(PyObject o)
    • py2char

      public static char py2char(PyObject o, String msg)
    • py2void

      public static void py2void(PyObject o)
    • makeCharacter

      public static final PyString makeCharacter(Character o)
    • makeCharacter

      public static final PyString makeCharacter(char c)
    • java2py

      public static PyObject java2py(Object o)
      Uses the PyObjectAdapter passed to PySystemState.initialize() to turn o into a PyObject.
      See Also:
    • javas2pys

      public static PyObject[] javas2pys(Object... objects)
      Uses the PyObjectAdapter passed to PySystemState.initialize() to turn objects into an array of PyObjects.
      See Also:
    • getAdapter

      public static ExtensiblePyObjectAdapter getAdapter()
      Returns:
      the ExtensiblePyObjectAdapter used by java2py.
    • makeClass

      public static PyObject makeClass(String name, PyObject[] bases, PyCode code)
    • makeClass

      public static PyObject makeClass(String name, PyObject[] bases, PyCode code, PyObject[] closure_cells)
    • makeClass

      public static PyObject makeClass(String name, PyObject base, PyObject dict)
    • makeClass

      public static PyObject makeClass(String name, PyObject[] bases, PyObject dict)
      Create a new Python class.
      Parameters:
      name - the String name of the class
      bases - an array of PyObject base classes
      dict - the class's namespace, containing the class body definition
      Returns:
      a new Python Class PyObject
    • getName

      public static String getName()
    • getCompilerFlags

      public static CompilerFlags getCompilerFlags()
    • getCompilerFlags

      public static CompilerFlags getCompilerFlags(int flags, boolean dont_inherit)
    • getCompilerFlags

      public static CompilerFlags getCompilerFlags(CompilerFlags flags, boolean dont_inherit)
    • compile

      public static PyCode compile(InputStream istream, String filename, CompileMode kind)
    • compile_flags

      public static PyCode compile_flags(org.python.antlr.base.mod node, String name, String filename, boolean linenumbers, boolean printResults, CompilerFlags cflags)
      Entry point for compiling modules.
      Parameters:
      node - Module node, coming from the parsing process
      name - Internal name for the compiled code. Typically generated by calling getName().
      filename - Source file name
      linenumbers - True to track source line numbers on the generated code
      printResults - True to call the sys.displayhook on the result of the code
      cflags - Compiler flags
      Returns:
      Code object for the compiled module
    • compile_flags

      public static PyCode compile_flags(org.python.antlr.base.mod node, String filename, CompileMode kind, CompilerFlags cflags)
    • compile_flags

      public static PyCode compile_flags(InputStream istream, String filename, CompileMode kind, CompilerFlags cflags)
      Compiles python source code coming from a file or another external stream
    • compile_flags

      public static PyCode compile_flags(String data, String filename, CompileMode kind, CompilerFlags cflags)
      Compiles python source code coming from String (raw bytes) data. If the String is properly decoded (from PyUnicode) the PyCF_SOURCE_IS_UTF8 flag should be specified.
    • compile_command_flags

      public static PyObject compile_command_flags(String string, String filename, CompileMode kind, CompilerFlags cflags, boolean stdprompt)
    • unpackSequence

      public static PyObject[] unpackSequence(PyObject obj, int length)
    • iter

      public static PyObject iter(PyObject seq, String message)
    • id

      public static long id(PyObject o)
    • idstr

      public static String idstr(PyObject o)
    • java_obj_id

      public static long java_obj_id(Object o)
    • printResult

      public static void printResult(PyObject ret)
    • saveClassFile

      public static void saveClassFile(String name, ByteArrayOutputStream bytestream)
    • isInstance

      public static boolean isInstance(PyObject inst, PyObject cls)
    • isSubClass

      public static boolean isSubClass(PyObject derived, PyObject cls)
    • javaPyClass

      public static PyObject javaPyClass(PyObject cls, Class<?> interfce)
      Returns a Python-class that extends cls and interfce. If cls already extends interfce, simply cls is returned. Otherwise a new class is created (if not yet cached). It caches such classes and only creates a new one if no appropriate class was cached yet.
      Returns:
      a Python-class that extends cls and interfce
    • newJ

      public static <T> T newJ(PyObject cls, Class<T> jcls, Object... args)
      This method is a compact helper to access Python-constructors from Java. It creates an instance of cls and retruns it in form of jcls, which must be an interface. This method even works if cls does not extend jcls in Python-code. In that case, it uses javaPyClass(PyObject, Class) to create an appropriate class on the fly.

      It automatically converts args to PyObjects.
      For keyword-support use newJ(PyObject, Class, String[], Object...).

      Parameters:
      cls - - the class to be instanciated
      jcls - - the Java-type to be returned
      args - are automatically converted to Jython-PyObjects
      Returns:
      an instance of cls in form of the interface jcls
      See Also:
    • newJ

      public static <T> T newJ(PyObject cls, Class<T> jcls, PyObject[] args, String[] keywords)
      This method is a compact helper to access Python-constructors from Java. It creates an instance of cls and retruns it in form of jcls, which must be an interface. This method even works if cls does not extend jcls in Python-code. In that case, it uses javaPyClass(PyObject, Class) to create an appropriate class on the fly.

      keywordss are applied to the last args in the list.

      Parameters:
      cls - - the class to be instanciated
      jcls - - the Java-type to be returned
      keywords - are applied to the last args
      args - for the Python-class constructor
      Returns:
      an instance of cls in form of the interface jcls
      See Also:
    • newJ

      public static <T> T newJ(PyObject cls, Class<T> jcls, String[] keywords, Object... args)
      This method is a compact helper to access Python-constructors from Java. It creates an instance of cls and retruns it in form of jcls, which must be an interface. This method even works if cls does not extend jcls in Python-code. In that case, it uses javaPyClass(PyObject, Class) to create an appropriate class on the fly.

      It automatically converts args to PyObjects.
      keywordss are applied to the last args in the list.

      Parameters:
      cls - - the class to be instanciated
      jcls - - the Java-type to be returned
      keywords - are applied to the last args
      args - are automatically converted to Jython-PyObjects
      Returns:
      an instance of cls in form of the interface jcls
      See Also:
    • newJ

      public static <T> T newJ(PyModule module, Class<T> jcls, Object... args)
      Works like newJ(PyObject, Class, Object...), but looks up the Python-class in the module-dict using the interface-name, i.e. jcls.getSimpleName().

      For keywords-support use newJ(PyModule, Class, String[], Object...).

      Parameters:
      module - the module containing the desired class
      jcls - Java-type of the desired clas, must have the same name
      args - constructor-arguments
      Returns:
      a new instance of the desired class
      See Also:
    • newJ

      public static <T> T newJ(PyModule module, Class<T> jcls, String[] keywords, Object... args)
      Works like newJ(PyObject, Class, String[], Object...), but looks up the Python-class in the module-dict using the interface-name, i.e. jcls.getSimpleName().

      keywordss are applied to the last args in the list.

      Parameters:
      module - the module containing the desired class
      jcls - Java-type of the desired class, must have the same name
      keywords - are applied to the last args in the list
      args - constructor-arguments
      Returns:
      a new instance of the desired class
      See Also: