How to pass multiple variable from php to python script

假装没事ソ 提交于 2019-12-01 17:46:43

问题


I need help on this x-x

assuming my php has 3 variables

<?php
$var1 = "1";
$var2 = "2";
$var3 = "3";
?>

So on the "exec" part im a bit stuck and confused, how do i pass those 3 variable into my python script, and how do i receive those 3 variables in my python script?


回答1:


You just pass them as command line arguments:

exec ( "/path/to/python/script.py $var1 $var2 $var3" );

Then in your Python script you can read them like this:

import sys

print sys.argv[1] # first parameter
print sys.argv[2] # second parameter
print sys.argv[3] # third parameter

Btw: sys.argv[0] contains the name of your script, that is why you start with index 1.

http://www.tutorialspoint.com/python/python_command_line_arguments.htm



来源:https://stackoverflow.com/questions/13758299/how-to-pass-multiple-variable-from-php-to-python-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!