小编m.w*_*ski的帖子

为什么zip对象消失了?

请查看代码,为什么列表(w)正确显示,并且h什么都不显示?

>>> x=[1,2,3]
>>> y=[4,5,6]
>>> w=zip(x,y)
>>> list(w)
[(1, 4), (2, 5), (3, 6)]
>>> h=list(w)
>>> h
[]
Run Code Online (Sandbox Code Playgroud)

python python-3.x

3
推荐指数
1
解决办法
56
查看次数

Cmd 模块属性错误

我正在尝试使用 python 的 cmd 模块,并且在 python 3.2 中编译此代码时,我在网站中获得了此测试代码

import cmd
import os

class ShellEnabled(cmd.Cmd):

    last_output = ''

    def do_shell(self, line):
        "Run a shell command"
        print ("running shell command:", line)
        output = os.popen(line).read()
        print (output)
        self.last_output = output

    def do_echo(self, line):
        "Print the input, replacing '$out' with the output of the last shell command"
        # Obviously not robust
        print (line.replace('$out', self.last_output))

    def do_EOF(self, line):
        return True

if __name__ == '__main__':
    ShellEnabled().cmdloop()
Run Code Online (Sandbox Code Playgroud)

我收到 cmd 模块的此错误。

AttributeError: 'module' object has no attribute 'Cmd' …
Run Code Online (Sandbox Code Playgroud)

python cmd attributeerror

3
推荐指数
1
解决办法
7576
查看次数

标签 统计

python ×2

attributeerror ×1

cmd ×1

python-3.x ×1