Python:如何仅在命令中获取字符串

问题描述 投票:0回答:1

由于某种原因,命令的字符串为我提供了内存引用,而不是我在此示例中寻找的简单“ pwd”

Command is (<tests/olv/olv/install/auto_ovirt_st_setup.InstallTest instance at 0xec118b4c>, 'pwd')

记录代码

def run_command_checking_exit_code(*command):
    """ Runs a command"""
    Log.info("Command is " + str(command))

def install_lago(self):
    command = ["ls", "-l"]
    self.run_command_checking_exit_code('pwd')
    """run the conductor profiles required to install OLVM """
    #Log.test_objective('TODO')
    #run_command_checking_exit_code('ls -al')
    """
    yum_list = ["epel-release", "centos-release-qemu-ev", "python-devel", "libvirt", "libvirt-devel", "libguestfs-tools", "libguestfs-devel", "gcc", "libffi-devel", "openssl-devel", "qemu-kvm-ev"]
    for yum in yum_list

    ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST + ' -t OS_OL7U6_X86_64_PVHVM_30GB -c 10.1.0.10 -o ' + self.log_jobdir_cc +'/vm_install_ol7.6', timeout=1000000)
    if ret:
        self.tc_fail('Creation of OLV Engine VM failed')
    ret, msg, tup = self.client.run('/qa/conductor/tests/' + OSSE_OLV_VERSION + '/installer/installerfactory.py -s ' + OSSE_OLV_ENGINE_HOST +' -p ovirt-engine -c 10.1.0.10 -o ' + self.log_jobdir_cc + '/engine_deploy', timeout=1000000)
    if ret:
        self.tc_fail('Install of OLV Engine Host failed')
    self.tc_pass('OLV Engine Host installed')
    """

def main(self):
    self.install_lago()

def __init__(self):
    self.main()
python pexpect
1个回答
0
投票

假设run_command_checking_exit_code与其他方法是同一类的一部分,它应该在其arg列表中包含self:def run_command_checking_exit_code(self, command)

您无需在方法定义中使用*,您只需将字符串传递给方法,并且只需使用command就可以打印该字符串。

© www.soinside.com 2019 - 2024. All rights reserved.