2017-01-25 91 views
1

我有幾個函數,我正在使用,我試圖使用.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 
+0

你試過使用string.replace()方法嗎? –

回答

2

首先,cmd成爲一個列表,通過展開周圍[.....]改變它變成一個字符串

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

list(args),storage_id,horcm_num是列表。它們需要作爲字符串的參數傳遞,而不是列表;使用func(*...)擴大名單參數:

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