我正在从我的php运行python脚本:
<?php
$command = escapeshellcmd('<path>/myscript.py');
$output = shell_exec($command);
echo $output;
?>
现在我需要将python脚本中的二维字符串数组传递给php页面,但我很困惑。当然,$output
将包含整个数组的单个字符串。我也考虑过json,但在这种情况下我应该将python数组转换为json字符串(这可能是另一个问题)....
答案 0 :(得分:3)
如果您的阵列不是太奇特,那么您的JSON构思应该可以正常工作。我构建了一个小的python脚本(public class ExceptionHandlingThreadGroup extends ThreadGroup {
private UncaughtExceptionHandler uncaughtExceptionHandler;
public ExceptionHandlingThreadGroup(String name) {
super(name);
}
public ExceptionHandlingThreadGroup(ThreadGroup parent, String name) {
super(parent, name);
}
public UncaughtExceptionHandler getUncaughtExceptionHandler() {
return this.uncaughtExceptionHandler;
}
public void setUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) {
this.uncaughtExceptionHandler = uncaughtExceptionHandler;
}
@Override
public void uncaughtException(Thread t, Throwable e) {
if (this.uncaughtExceptionHandler != null)
this.uncaughtExceptionHandler.uncaughtException(t, e);
else
super.uncaughtException(t, e);
}
}
)来提供php脚本(UncaughtExceptionHandler
):
test.py:
test.py
test.php的:
test.php