将值从PHP脚本传递到Python脚本 [英] Passing value from PHP script to Python script
问题描述
我看了其他与此问题类似的问题,但仍无法解决.
I looked at the other questions similar to this one, but can't figure this out still.
我有一个执行此操作的基本php文件:
I have a basic php file that does this:
?php
$item='example';
$tmp = exec("python testscriptphp.py .$item");
echo $tmp;
?
虽然成功调用了我在webhostserver上运行的python.现在在我的python脚本中,我想要这样的东西:
While succesfully calls python that I have running on my webhostserver. Now in my python script i want something like this:
item=$item
print item
基本上,我问的是如何将变量从PHP传递到python脚本,然后在必要时将其传递回php.
Basically I'm asking how to pass variables from PHP to a python script and then back to php if necessary.
谢谢!
推荐答案
尽管netcoder在他的评论中给了您很多答案,但这是一个示例:
Although netcoder pretty much gave you the answer in his comment, here's an example:
Python-> PHP
Python->PHP
example.py
example.py
import os
os.system("/usr/bin/php example2.php whatastorymark")
example2.php
example2.php
<?php
echo $argv[1];
?>
PHP-> Python
PHP->Python
<?php
$item='example';
$tmp = exec("python testscriptphp.py .$item");
echo $tmp;
?>
testscriptphp.py
testscriptphp.py
import sys
print sys.argv[1]
这是PHP命令行参数传递的工作方式: http://php.net /manual/en/reserved.variables.argv.php 对于Python同样如此: http://docs.python.org/library/sys. html#sys.argv
Here's how PHP's command line argument passing works: http://php.net/manual/en/reserved.variables.argv.php The same for Python: http://docs.python.org/library/sys.html#sys.argv
这篇关于将值从PHP脚本传递到Python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!