當前位置: 首頁>>代碼示例>>Java>>正文


Java Py.newString方法代碼示例

本文整理匯總了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);
}
 
開發者ID:cpburnz,項目名稱:minecraft-mod-python,代碼行數:22,代碼來源:JavaMod.java

示例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);
}
 
開發者ID:cpburnz,項目名稱:minecraft-mod-python,代碼行數:42,代碼來源:Python.java

示例3: getcwd

import org.python.core.Py; //導入方法依賴的package包/類
public static PyObject getcwd() {
    return Py.newString(Py.getSystemState().getCurrentWorkingDir());
}
 
開發者ID:RunasSudo,項目名稱:PyAndroid,代碼行數:4,代碼來源:PosixModule.java

示例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);
}
 
開發者ID:cpburnz,項目名稱:minecraft-mod-python,代碼行數:12,代碼來源:Python.java


注:本文中的org.python.core.Py.newString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。