mySQL データベースを検索し、そのすべてのインスタンスを返す php スクリプトがあります。このインスタンス データ (文字列、文字列、文字列、(文字列、文字列、文字列、文字列) のリストのリスト) を Python スクリプトのパラメーターとして使用したいと思います。
では、このすべての情報を Python スクリプトに渡すにはどうすればよいでしょうか。exec を使用してスクリプトを実行することは知っていますが、リストのリストをパラメーターとして含めるにはどうすればよいですか?
<?php
$list = array('arg1', 'arg2');
exec(sprintf('python script.py %s', escapeshellarg(implode(' ', $list)));
次に、argparse を使用します: http://docs.python.org/library/argparse.html#module-argparse。
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