本文整理汇总了Java中org.python.core.Py.newString方法的典型用法代码示例。如果您正苦于以下问题:Java Py.newString方法的具体用法?Java Py.newString怎么用?Java Py.newString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.python.core.Py
的用法示例。
在下文中一共展示了Py.newString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preInit
import org.python.core.Py; //导入方法依赖的package包/类
/**
* Instantiate the python mod instance and send it the pre-initialization
* event.
*
* *event* is the pre-initialization event.
*/
public void preInit(FMLPreInitializationEvent event) {
// Instantiate python mod class.
final String moduleName = this.getPythonModuleName();
final String className = this.getPythonClassName();
final PyString pyClassName = Py.newString(className);
this.log.fine("Load %s.%s", moduleName, className);
final PyObject pyModule = PyMod.python.importModule(moduleName);
final PyObject pyModClass = pyModule.__getattr__(pyClassName);
final PyObject pyModInst = pyModClass.__call__();
this.pythonMod = (IPythonMod)pyModInst.__tojava__(IPythonMod.class);
// Call mod pre-init.
this.log.fine("Pre-initialization.");
this.pythonMod.preInit(event);
}
示例2: Python
import org.python.core.Py; //导入方法依赖的package包/类
/**
* Initializes the ``Python`` instance.
*/
public Python() {
// Create logger.
final String logName = "pymod:" + this.getClass().getSimpleName();
this.log = new Logger(logName);
// Create python system state.
this.log.fine("Create system state.");
this.sys = new PySystemState();
// Create python interpreter.
this.log.fine("Create interpreter.");
this.interpreter = new PythonInterpreter(null, this.sys);
// Add java class loader path to python import path.
// - NOTE: This is only needed if importing python modules from the
// file system (not from JARs).
/*
FMLLog.log("PyMod", Level.INFO, "Get class loader path."); // XXX
final URL resource = this.getClass().getClassLoader().getResource(".");
if (resource != null) {
FMLLog.log("PyMod", Level.INFO, "Add class loader path."); // XXX
this.state.path.insert(0, new PyString(resource.getPath()));
}
*/
// Initialize python environment.
this.log.fine("Initialize python environment.");
final PyString pyModuleName = Py.newString(this.getClass().getPackage().getName() + ".py");
final PyString PyInitName = Py.newString("__init__");
final PyObject pyModule = this.importModule(pyModuleName);
final PyObject pyInitFunc = pyModule.__getattr__(PyInitName);
pyInitFunc.__call__();
// Get importer.
this.log.fine("Get importer.");
final PyString pyImportName = Py.newString("__import__");
this.importer = this.sys.getBuiltins().__getitem__(pyImportName);
}
示例3: getcwd
import org.python.core.Py; //导入方法依赖的package包/类
public static PyObject getcwd() {
return Py.newString(Py.getSystemState().getCurrentWorkingDir());
}
示例4: importModule
import org.python.core.Py; //导入方法依赖的package包/类
/**
* Helper method to import a python module.
*
* *moduleName* is the python module to import.
*
* Returns the python module.
*/
public PyObject importModule(String moduleName) {
final PyString pyModuleName = Py.newString(moduleName);
return this.importModule(pyModuleName);
}