当前位置: 首页>>代码示例>>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;未经允许,请勿转载。