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

由于某种原因,命令的字符串为我提供了内存引用,而不是我在此示例中寻找的简单“ 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,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()
calvin1 回答:Python:如何仅在命令中获取字符串

假设run_command_checking_exit_code与其他方法属于同一类,则它的arg列表中应包含self:def run_command_checking_exit_code(self,command)

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

其他几件事:

1)这里的main()方法不是真正需要的,您不应该具有仅代码行调用另一个函数的函数。

2)如果您想用列表而不是字符串来调用run_command_checking_exit_code(例如,将command = ['ls','-l']列表传递给它,那么您需要研究如何在Python中打印列表。搜索将为您展示实现该目标的几种方法。

本文链接:https://www.f2er.com/2830182.html

大家都在问