0

mySQL データベースを検索し、そのすべてのインスタンスを返す php スクリプトがあります。このインスタンス データ (文字列、文字列、文字列、(文字列、文字列、文字列、文字列) のリストのリスト) を Python スクリプトのパラメーターとして使用したいと思います。

では、このすべての情報を Python スクリプトに渡すにはどうすればよいでしょうか。exec を使用してスクリプトを実行することは知っていますが、リストのリストをパラメーターとして含めるにはどうすればよいですか?

4

2 に答える 2

0
<?php
    $list = array('arg1', 'arg2');
    exec(sprintf('python script.py %s', escapeshellarg(implode(' ', $list)));

次に、argparse を使用します: http://docs.python.org/library/argparse.html#module-argparse

于 2012-06-07T16:32:25.517 に答える
0

you cant well not exactly

you can use redirection to send text to the script

exec("something.py < inputstuff.txt");

or you can pass an argument list

exec("something.py arg1 arg2 arg3");

you could pass it in as a string representation and eval it inside the script or something if you use redirection the data should be available from sys.stdin if you pass it as an arg list the data should be available via sys.argv

于 2012-06-07T16:31:37.973 に答える