Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays Python3从列表创建数组(我想)_Arrays_Python 3.x_List - Fatal编程技术网

Arrays Python3从列表创建数组(我想)

Arrays Python3从列表创建数组(我想),arrays,python-3.x,list,Arrays,Python 3.x,List,我正在编写一个在两个windows/osx上运行的Python3脚本,它将基本上注销所有VirtualBox机器 为了做到这一点,我计划列出所有当前注册的机器,然后循环输出以注销每个机器 命令的输出 VBoxManage list vms 是 如何将双引号内的每个字符串转换为数组,然后使用取消注册的命令进行迭代 这就是我一直在尝试的 existing = os.system("VBoxManage list vms") machines = re.findall(r'"([^"

我正在编写一个在两个windows/osx上运行的Python3脚本,它将基本上注销所有VirtualBox机器

为了做到这一点,我计划列出所有当前注册的机器,然后循环输出以注销每个机器

命令的输出

VBoxManage list vms

如何将双引号内的每个字符串转换为数组,然后使用取消注册的命令进行迭代

这就是我一直在尝试的

    existing = os.system("VBoxManage list vms")
    machines = re.findall(r'"([^"]*)"', existing)
    for m in machines:
        print(m)
但是继续

TypeError: expected string or bytes-like object

os.system
的返回值不是命令的
stdout
,请参阅。因此,您无法在其上使用
re

您可能希望使用,如下所示:

with subprocess.Popen(["VBoxManage", "list", "vms"], stdout=PIPE) as proc:
    machines = re.findall(r'"([^"]*)"', (proc.stdout.read())
    ....
with subprocess.Popen(["VBoxManage", "list", "vms"], stdout=PIPE) as proc:
    machines = re.findall(r'"([^"]*)"', (proc.stdout.read())
    ....