有沒有一種方法可以在Java程式中編譯/檢查Python代碼(存盤在字串中)的錯誤。很多人都把Jython作為解決方案。如果是Jython,程式是什么?
uj5u.com熱心網友回復:
你可以做一些與此類似的事情:
Python代碼: import os
from stat import *
import csv
data = [] 。
with open('Example.csv') as f.
reader = csv.reader(f, delimiter = ', ')
for row in reader:
data.append(row)
f = open("Clearprint.csv"/span>,"w"/span>)
f.truncate()
f.關閉()
with open('Clearprint.csv','w',newline=' ') as fp:
a = csv.writer(fp,delimiter = ', ')
a.writerows(data)
Java代碼:
class test1{
public static void main title function_">main(String[] args) throwsIOException {
String pythonScriptPath = "our .py file path"。
String[] cmd = new String[2] 。
cmd[0] = "你的python.exe路徑"。
cmd[1] = pythonScriptPath;
Runtime rt = Runtime.getRuntime()。
Process pr = rt.exec(cmd) 。
BufferedReader err = new BufferedReader(new InputStreamReader(pr. getErrorStream()))。)
String line = ""/span>;
while((line = err.readLine()) != null) {
System.err.println(line)。
}
}
}
uj5u.com熱心網友回復:
我沒有足夠的代表來評論這個問題,但這個問題可能就是你要找的用java編譯python代碼。 一個用戶提到了 "Jython",這可能是符合你的描述的。
只是一個警告。如果你有一個內部的IDE,讓人們在你的Java應用中練習Python(我推測),要警惕回傳的錯誤資訊混淆用戶,因為Python和java的反饋不盡相同。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/331552.html
標籤:
