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

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

        • <bdo id='yVWlH'></bdo><ul id='yVWlH'></ul>
      1. 出现错误 - AttributeError: 'module' object has no attrib

        时间:2023-07-21
      2. <small id='r7E4z'></small><noframes id='r7E4z'>

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

              <tfoot id='r7E4z'></tfoot>
                <tbody id='r7E4z'></tbody>

                  本文介绍了出现错误 - AttributeError: 'module' object has no attribute 'run' while running subprocess.run(["ls", "-l"])的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 AIX 6.1 上运行并使用 Python 2.7.想要执行以下行,但出现错误.

                  I am running on a AIX 6.1 and using Python 2.7. Want to execute following line but getting an error.

                  subprocess.run(["ls", "-l"])
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  AttributeError: 'module' object has no attribute 'run'
                  

                  推荐答案

                  subprocess.run()函数只存在于Python 3.5及更新版本.

                  The subprocess.run() function only exists in Python 3.5 and newer.

                  然而,向后移植很容易:

                  It is easy enough to backport however:

                  def run(*popenargs, **kwargs):
                      input = kwargs.pop("input", None)
                      check = kwargs.pop("handle", False)
                  
                      if input is not None:
                          if 'stdin' in kwargs:
                              raise ValueError('stdin and input arguments may not both be used.')
                          kwargs['stdin'] = subprocess.PIPE
                  
                      process = subprocess.Popen(*popenargs, **kwargs)
                      try:
                          stdout, stderr = process.communicate(input)
                      except:
                          process.kill()
                          process.wait()
                          raise
                      retcode = process.poll()
                      if check and retcode:
                          raise subprocess.CalledProcessError(
                              retcode, process.args, output=stdout, stderr=stderr)
                      return retcode, stdout, stderr
                  

                  不支持超时,也不支持完成进程信息的自定义类,所以我只返回 retcodestdoutstderr信息.否则它和原来的一样.

                  There is no support for timeouts, and no custom class for completed process info, so I'm only returning the retcode, stdout and stderr information. Otherwise it does the same thing as the original.

                  这篇关于出现错误 - AttributeError: 'module' object has no attribute 'run' while running subprocess.run(["ls", "-l"])的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                    <bdo id='oDppY'></bdo><ul id='oDppY'></ul>

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

                      1. <tfoot id='oDppY'></tfoot>
                      2. <small id='oDppY'></small><noframes id='oDppY'>

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

                            <tbody id='oDppY'></tbody>