Skip to main content
 首页 » 编程设计

带有子进程返回的 Python 脚本必须是 str,而不是 int evrything linter 说是这种情况

2024年12月31日9lidabo

<分区>

当我运行以下代码时出现以下错误。

版本信息:

Python 3.6.5 (default, May 11 2018, 04:00:52) [GCC 8.1.0] on linux

代码:

正确格式位于 https://gist.github.com/Drunkenpanda2000/31f76521ce1166b804a539f40ec21c60

#!/usr/bin/env python 
 
import subprocess 
 
#will be replaced with inputs from Chef 
 
name='test'  
vcpus=1  
memory=2048  
iso='/var/lib/libvirt/images/Centos.iso'  
discsize= 80  
os_type='linux'  
os_variant='centos7'  
network_bridge='default' 
 
#setting up the command 
 
args = ( 
    'virt-install' +  
    ' --name=' + name +  
    ' --vcpus=' + vcpus +  
    ' --memory=' + memory +  
    ' --cdrom=' + iso +  
    ' --disk size=' + discsize +  
    ' --os-type=' + os_type +  
    ' --os-varient=' + os_variant + 
    ' --network bridge=' + network_bridge + 
    " --extra-args 'console=ttyS0,115200n8 serial'" ) 
 
#execute the commands in bash 
 
subprocess.call(args, shell=True) 

错误

[drunkenpanda@Diablo Scripts]$ ./createvm.py  Traceback (most recent call last):   File "./createvm.py", line 27, in <module> 
    ' --network bridge=' + network_bridge + TypeError: must be str, not int 

新代码

    args = ['virt-install', 
    ' --name',name, 
    ' --vcpus',str(vcpus), 
    ' --memory',str(memory), 
    ' --cdrom',iso, 
    ' --disk-size',str(discsize), 
    ' --os-variant',os_variant, 
    ' --os-type',os_type, 
    ' --network bridge',network_bridge] 
 
 
    # " --extra-args 'console=ttyS0,115200n8 serial'"\ 
 
 
#execute the commands in bash 
 
subprocess.call(args, shell=False) 

新错误

./createvmattend.1.py  
usage: virt-install --name NAME --memory MB STORAGE INSTALL [options] 
virt-install: error: unrecognized arguments:  --name bob  --vcpus 1  --memory 2048  --cdrom /var/lib/libvirt/images/Centos.iso  --disk-size 80  --os-variant centos7.0  --os-type linux  --network bridge virbr0