python - 删除输出中的括号和引号

标签 python python-3.x

我正在使用几个函数,并且尝试使用 .split() 删除括号,但括号和引号仍然显示在输出中。我将这些函数分开,因为我计划在许多不同的函数中调用 fn_run_cmd

def fn_run_cmd(*args):
    cmd = ['raidcom {} -s {} -I{}'.format(list(args),
           storage_id, horcm_num)]
    print(cmd)

def fn_find_lun(ldev, port, gid):
    result = fn_run_raidcom('get lun -port {}-{}'.format(port, gid))
    return(result)
    match = re.search(r'^{} +{} +\S+ +(?P<lun>\d+) +1 +{} '.format(
                  port, gid, ldev), result[1], re.M)
    if match:
        return(match.group('lun'))
    return None

下面是我得到的输出:

"raidcom ['get lun -port CL1-A-2'] -s [987654] -I[99]"

期望的结果:

raidcom get lun -port CL1-A-2 -s 987654 -I99

最佳答案

首先,cmd成为一个列表,通过解包周围的[.....]将其更改为字符串

cmd = 'raidcom {} -s {} -I{}'.format(list(args),
      storage_id, horcm_num)

list(args)storage_idhorcm_num 是列表。它们需要作为字符串参数传递,而不是列表;使用 func(*...) 将列表扩展为参数:

def fn_run_cmd(*args):
    cmd = 'raidcom {} -s {} -I{}'.format(*list(args) + storage_id + horcm_num)
    print(cmd)

关于python - 删除输出中的括号和引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41863461/

相关文章:

python - 如何将路径的 (X,Y) 坐标列表拆分为单独的 X 和 Y 坐标列表?

python - Pandas 将一列的列表元素的值分配到 n 个不同的列中

python-2.7 - 如何在 Python 2 中模仿 Python 3 的加薪...?

python-3.x - 从多类分类算法输出前 2 个类

Python项目结构,项目主文件导入助手

Python Socket异步收发设计

python - 在不使用 sum() 的情况下打印整数列表的总和

python - 在Python asyncio中创建并发任务之间的依赖关系

python - 在 Python3 中对具有 None 值的元组列表进行排序

python-3.x - 在将 Keras Tuner 与 Tensorflow 2 结合使用时,出现错误 : division by zero