1. <tfoot id='k51Xs'></tfoot>
    <legend id='k51Xs'><style id='k51Xs'><dir id='k51Xs'><q id='k51Xs'></q></dir></style></legend>

    • <bdo id='k51Xs'></bdo><ul id='k51Xs'></ul>
    <i id='k51Xs'><tr id='k51Xs'><dt id='k51Xs'><q id='k51Xs'><span id='k51Xs'><b id='k51Xs'><form id='k51Xs'><ins id='k51Xs'></ins><ul id='k51Xs'></ul><sub id='k51Xs'></sub></form><legend id='k51Xs'></legend><bdo id='k51Xs'><pre id='k51Xs'><center id='k51Xs'></center></pre></bdo></b><th id='k51Xs'></th></span></q></dt></tr></i><div id='k51Xs'><tfoot id='k51Xs'></tfoot><dl id='k51Xs'><fieldset id='k51Xs'></fieldset></dl></div>
    1. <small id='k51Xs'></small><noframes id='k51Xs'>

      从另一个脚本启动 python 脚本,参数在子进程参数中

      时间:2023-07-22

      <tfoot id='w2DMF'></tfoot>
        <i id='w2DMF'><tr id='w2DMF'><dt id='w2DMF'><q id='w2DMF'><span id='w2DMF'><b id='w2DMF'><form id='w2DMF'><ins id='w2DMF'></ins><ul id='w2DMF'></ul><sub id='w2DMF'></sub></form><legend id='w2DMF'></legend><bdo id='w2DMF'><pre id='w2DMF'><center id='w2DMF'></center></pre></bdo></b><th id='w2DMF'></th></span></q></dt></tr></i><div id='w2DMF'><tfoot id='w2DMF'></tfoot><dl id='w2DMF'><fieldset id='w2DMF'></fieldset></dl></div>
      1. <legend id='w2DMF'><style id='w2DMF'><dir id='w2DMF'><q id='w2DMF'></q></dir></style></legend>

          <small id='w2DMF'></small><noframes id='w2DMF'>

            <bdo id='w2DMF'></bdo><ul id='w2DMF'></ul>
              <tbody id='w2DMF'></tbody>

                本文介绍了从另一个脚本启动 python 脚本,参数在子进程参数中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                要从终端启动 python 脚本(运行 OLED 显示器需要它),我必须使用以下 bash 命令:python demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20..py 之后的那些参数很重要,否则,脚本将以默认设置运行,在我的情况下,脚本将不会以默认设置启动.因此,需要这些参数.

                To launch a python script (it is needed for running an OLED display) from terminal, I have to use the following bash commands: python demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20. Those parameters after .py are important, otherwise, the script will run with default settings and in my case, the script will not launch with default settings. Thus, those parameters are needed.

                当我需要从另一个 python 脚本启动我的脚本(而不是在终端上使用 bash 命令)时,就会出现问题.从父脚本启动我的 python 脚本之一.我用过:

                The problem arises when I need to launch my script from another python script, (instead of using bash commands on terminal). To launch one of my python script from a parent script. I have used:

                import subprocess # to use subprocess 
                
                p = subprocess.Popen(['python', 'demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20'])
                

                在我的父脚本中,但我收到一条错误消息:

                in my parent script but I got an error stating:

                python: 无法打开文件 'demo_oled_v01.py --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20': [Errno 2] 没有这样的文件或目录

                我怀疑在 .py 之后添加参数 --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20可能会导致启动脚本困难.如前所述,这些参数对于我在终端上使用 bash 命令启动是必不可少的.如何使用带有所需参数的子进程来启动此脚本?

                I suspect that adding the parameters --display ssd1351 --width 128 --height 128 --interface spi --gpio-data-command 20 after .py may be causing difficulty in launching the script. As mentioned, these parameters are otherwise essential for me to include for launching with bash commands on terminal. How can I use subprocess with the required parameters to launch this script?

                推荐答案

                subprocess 库正在解释您的所有参数,包括 demo_oled_v01.py 作为单个参数Python.这就是为什么 python 抱怨它无法找到具有该名称的文件的原因.尝试运行它:

                The subprocess library is interpreting all of your arguments, including demo_oled_v01.py as a single argument to python. That's why python is complaining that it cannot locate a file with that name. Try running it as:

                p = subprocess.Popen(['python', 'demo_oled_v01.py', '--display',
                'ssd1351', '--width', '128', '--height', '128', '--interface', 'spi',
                '--gpio-data-command', '20'])
                

                查看更多关于 Popen 的信息这里.

                See more information on Popen here.

                这篇关于从另一个脚本启动 python 脚本,参数在子进程参数中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 pythonw.exe 时 Python subprocess.call() 失败 下一篇:使用选定的浏览器启动 IPython 笔记本

                相关文章

              • <small id='laq6v'></small><noframes id='laq6v'>

                <legend id='laq6v'><style id='laq6v'><dir id='laq6v'><q id='laq6v'></q></dir></style></legend>

                  • <bdo id='laq6v'></bdo><ul id='laq6v'></ul>
                  <tfoot id='laq6v'></tfoot>

                  1. <i id='laq6v'><tr id='laq6v'><dt id='laq6v'><q id='laq6v'><span id='laq6v'><b id='laq6v'><form id='laq6v'><ins id='laq6v'></ins><ul id='laq6v'></ul><sub id='laq6v'></sub></form><legend id='laq6v'></legend><bdo id='laq6v'><pre id='laq6v'><center id='laq6v'></center></pre></bdo></b><th id='laq6v'></th></span></q></dt></tr></i><div id='laq6v'><tfoot id='laq6v'></tfoot><dl id='laq6v'><fieldset id='laq6v'></fieldset></dl></div>