How to pass multiple variable from php to python script

后端 未结 1 2019
北恋
北恋 2021-01-18 15:57

I need help on this x-x

assuming my php has 3 variables


So on the \"exe

相关标签:
1条回答
  • 2021-01-18 16:41

    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

    0 讨论(0)
提交回复
热议问题