interpreter什么时候开始?

bk2898 76 0

interpreter什么时候开始?

interpreter的起源可以追溯到计算机发明之初,但是具体的开始时间很难确定。一般认为,之一个interpreter是由John Backus在1954年开发的,用于Fortran语言。但是,也有一些人认为,之一个interpreter是由Christopher Strachey在1951年开发的,用于ALGOL语言。总的来说,interpreter的发展是一个逐步完善的过程,随着计算机技术的不断进步,interpreter也在不断地发展和改进。

interpreter都有哪些词性?

1 interpreter的词性包括名词和动词。2 名词interpreter作为名词,指的是一种将源代码逐行翻译并执行的计算机程序或软件。它可以将高级语言代码转换为机器语言或者中间代码,实现程序的运行。3 动词interpreter作为动词,指的是或翻译某种语言或者信息。在计算机领域中,interpreter动词形式指的是执行型语言的操作,逐行并执行代码。4 除了interpreter这个词性外,还有其他与interpreter相关的词性,如interpreting(名词),interpreted(形容词)等。这些词性都与、翻译和执行代码相关,是计算机编程领域中重要的概念。

分享相关内容的知识扩展阅读:

为什么beautifulsoup安装成功但不能调用

首先,你要先进入pycharm的Project Interpreter界面,进入 *** 是:setting(ctrl+alt+s) ->Project Interpreter,Project Interpreter在具体的Project下。如下图所示:点击“+”,输入beautifulsoup ,就可以找到你要安装的插件了。

java调用python,有第三方包gensim,怎么调用呢,是报错。求教....

Jython(原JPython),是一个用Java语言写的Python解释器。

在没有第三方模块的情况下,通常选择利用Jython来调用Python代码,

它是一个开源的JAR包,你可以到官网下载

一个HelloPython程序

import org.python.util.PythonInterpreter;

public class HelloPython {

public static void main(String[] args) {

PythonInterpreter interpreter = new PythonInterpreter();

interpreter.exec("print('hello')");

}

}

什么是PythonInterpreter?它的中文意思即是“Python解释器”。我们知道Python程序都是通过解释器来执行的,我们在Java中创建一个“解释器”对象,模拟Python解释器的行为,通过exec("Python语句")直接在JVM中执行Python代码,上面代码的输出结果为:hello

 

在Jvm中执行Python脚本

interpreter.execfile("D:/labs/mytest/hello.py");  

 

如上,将exec改为execfile就可以了。需要注意的是,这个.py文件不能含有第三方模块,因为这个“Python脚本”最终还是在JVM环境下执行的,如果有第三方模块将会报错:java ImportError: No module named xxx

仅在Java中调用Python编写的函数

先完成一个hello.py代码:

def hello():

return 'Hello'

 

在Java代码中调用这个函数:

import org.python.core.PyFunction;

import org.python.core.PyObject;

import org.python.util.PythonInterpreter;

public class HelloPython {

public static void main(String[] args) {

PythonInterpreter interpreter = new PythonInterpreter();

interpreter.execfile("D:/labs/hello.py");

PyFunction pyFunction = interpreter.get("hello", PyFunction.class); // 之一个参数为期望获得的函数(变量)的名字,第二个参数为期望返回的对象类型

PyObject pyObject = pyFunction.__call__(); // 调用函数

System.out.println(pyObject);

}

}

上面的代码执行结果为:Hello

即便只是调用一个函数,也必须先加载这个.py文件,之后再通过Jython包中所定义的类获取、调用这个函数。

如果函数需要参数,在Java中必须先将参数转化为对应的“Python类型”,例如:

__call__(new PyInteger(a), new PyInteger(b))

 

a,b的类型为Java中的int型,还有诸如:PyString(String string)、PyList(Iterator<PyObject> iter) 等。

详细可以参考官方的api文档。

包含第三方模块的情况:一个手写识别程序

这是我和舍友合作写的一个小程序,完整代码在这里:

handwrite源代码来自:百度网盘点击跳转网盘

 ,界面上引用了core java上的一段代码。Python代码是舍友写的,因为在Python程序中使用了第三方的NumPy模块,导致无法通过Jython执行。这个 *** 纯粹是个人思路,没有深入查资料。 核心代码如下:

import java.io.*;

class PyCaller {

private static final String DATA_SWAP = "temp.txt";

private static final String PY_URL = System.getProperty("user.dir") + "\\test.py";

public static void writeImagePath(String path) {

PrintWriter pw = null;

try {

pw = new PrintWriter(new FileWriter(new File(DATA_SWAP)));

} catch (IOException e) {

e.printStackTrace();

}

pw.print(path);

pw.close();

}

public static String readAnswer() {

BufferedReader br;

String answer = null;

try {

br = new BufferedReader(new FileReader(new File(DATA_SWAP)));

answer = br.readLine();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

return answer;

}

public static void execPy() {

Process proc = null;

try {

proc = Runtime.getRuntime().exec("python " + PY_URL);

proc.waitFor();

} catch (IOException e) {

e.printStackTrace();

} catch (InterruptedException e) {

e.printStackTrace();

}

}

// 测试码

public static void main(String[] args) throws IOException, InterruptedException {

writeImagePath("D:\\labs\\mytest\\test.jpg");

execPy();

System.out.println(readAnswer());

}

}

实际上就是通过Java执行一个命令行指令。

-bash: /bin/tar: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录现在什么命令都用不了

j就可以CD更好能加 *** 指导,感激不尽
[root@ www.linuxidc.com server]# javac -version -bash: /server/jdk1.7/bin/javac: /lib/ld-linux.so.2: bad ELF interpreter: 没有那个文件或目录 解决: 找到系统光盘里的rpm 包,安装 glibc包 和nss包:(可能有一些不用也行,但还是把的包都装了) glib2-2.22.5-5.el6.i686.rpm glib2-2.22.5-5.el6.x86_64.rpm glib2-devel-2.22.5-5.el6.i686.rpm glib2-devel-2.22.5-5.el6.x86_64.rpm glibc-2.12-1.7.el6.i686.rpm glibc-2.12-1.7.el6.x86_64.rpm glibc-common-2.12-1.7.el6.x86_64.rpm glibc-devel-2.12-1.7.el6.i686.rpm glibc-devel-2.12-1.7.el6.x86_64.rpm glibc-headers-2.12-1.7.el6.x86_64.rpm glibc-utils-2.12-1.7.el6.x86_64.rpm glibmm24-2.22.1-1.el6.x86_64.rpm nss-softokn-freebl-3.12.7-1.1.el6.i686.rpm nss-softokn-freebl-3.12.7-1.1.el6.x86_64.rpm [root@ www.linuxidc.com ld-linux.so.2]# rpm -ivh * --force --nodeps 再重新测试,成功! 本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-08/68889.htm

抱歉,评论功能暂时关闭!