【问题标题】:Subprocess.check_output doesn't workSubprocess.check_output 不起作用
【发布时间】:2013-08-12 09:42:43
【问题描述】:

当我在 Subprocess 模块中使用 check_output 时,Python shell 出现以下输出错误:

AttributeError: 'module' 对象没有属性 'check_output'

代码:

target = raw_input("IP: ")
port = subprocess.check_output(["python", "portscanner.py", target ])

我使用 Python 2.7。感谢您的解决方案!

【问题讨论】:

  • print subprocess.__file__ 说的是模块的位置?此外,.check_output() 仅在 Python 2.7 中添加,因此请确保您运行的是正确的 Python 版本。

标签: python python-2.7 subprocess


【解决方案1】:

check_output() 方法是在python2.7 及以后定义的,正如“Martijn Pieters”所说

签入 subprocess.py 行号:515

def check_output(*popenargs, **kwargs):

您可能正在使用旧的 python 版本,或者您可能弄乱了 python 解释器。

尝试使用

dir(module[.class]) 

在任何模块中查找可用的方法或类并继续。

【讨论】:

    猜你喜欢
    • 2019-04-18
    • 2014-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2019-07-12
    • 2012-11-10
    • 2015-05-04
    相关资源
    最近更新 更多