如何将多个变量从php传递到python脚本 [英] How to pass multiple variable from php to python script

查看:98
本文介绍了如何将多个变量从php传递到python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对此xx进行帮助

I need help on this x-x

假设我的php有3个变量

assuming my php has 3 variables

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

因此,在 exec部分,我有点困惑,我该如何传递这3个变量到我的python脚本中,如何在我的python脚本中接收这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?

推荐答案

您只需将它们作为命令行传递参数:

You just pass them as command line arguments:

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

然后在您的Python脚本中,您可以像这样读取它们:

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] 包含脚本的名称,这就是为什么从索引 1 开始的原因。

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

这篇关于如何将多个变量从php传递到python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆