• 转 php 框架 Php 依赖框架 后台 调用python 脚本


    感谢 ruchee,Tim HallmanSMshrimant

    https://www.v2ex.com/t/351428

    https://stackoverflow.com/questions/19735250/running-a-python-script-from-php

    转 php 框架 Php 依赖框架 后台 调用python 脚本

    ##html 的按钮和其他选项框  起到 中介功能,调用后端。

    以下案例仅仅对windows php 调用python 脚本有效

    D:wamp64wwwapp  新建2个文件index.php 和 test.py

    index.php

    //php.php
    
    <html>
    <body>
    <head>
    <title>
    run
    </title>
    </head>
    
    <form method="post">
    
    <input type="submit" value="GO" name="GO">
    </form>
    </body>
    </html>
    
    <?php
    if(isset($_POST['GO']))
    {
    exec("D:/python3/python.exe D:/wamp64/www/peng/test.py 2>&1");
    echo"success";
    }
    ?>

    test.py

    #!D:python3python.exe
    # -*- coding: utf-8 -*- 
    import os    
    os.makedirs("thisfolder");
    

      

    http://localhost/app/index.php

    完成后,就会创建一个目录

    thisfolder


    ### 感谢

    https://blog.csdn.net/liao392781/article/details/80321614?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase



    a.py

    import sys

    #传入3个参数,具体操作根据个人情况
    def main(argv):
    print(argv[1])
    print(argv[2])
    print(argv[3])

    #if __name__ == "__main__":
    # main(sys.argv)
    a=sys.argv[1]
    b=sys.argv[2]
    c=sys.argv[3]

    f = open('d:/newfile.txt', 'w')
    f.write(a)
    f.write(b)
    f.write(c)
    f.close()

    执行过程

    python a.py 1 2  3

    ####2

    感谢jieliu8080

    import sys

    #传入3个参数,具体操作根据个人情况
    def main(argv):
    print(argv[1])
    print(argv[1][4])
    print(arr)
    # print(argv[2])
    # print(argv[3])

    a=sys.argv[1]
    arr=a.split(',')


    if __name__ == "__main__":
    main(sys.argv)


    f = open('d:/newfile.txt', 'w')
    f.write(a)
    f.close()

    字符串转数组
    str = '1,2,3'
    arr = str.split(',')

    数组转字符串
    arr = ['a','b']
    str = ','.join(arr)

    arr = [1,2,3]
    str = ','.join(str(i) for i in b)

  • 相关阅读:
    tyvj 1031 热浪 最短路
    【bzoj2005】 [Noi2010]能量采集 数学结论(gcd)
    hdu 1394 Minimum Inversion Number 逆序数/树状数组
    HDU 1698 just a hook 线段树,区间定值,求和
    ZeptoLab Code Rush 2015 C. Om Nom and Candies 暴力
    ZeptoLab Code Rush 2015 B. Om Nom and Dark Park DFS
    ZeptoLab Code Rush 2015 A. King of Thieves 暴力
    hdoj 5199 Gunner map
    hdoj 5198 Strange Class 水题
    vijos 1659 河蟹王国 线段树区间加、区间查询最大值
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/13213055.html
Copyright © 2020-2023  润新知