clarkus978
clarkus978

Reputation: 634

Removing Brackets and Quotes in Output

I've got a couple of functions that I'm working with and I've tried using .split() to remove the brackets, but the brackets and quotes still show in the output. I have the functions separate because I plan on calling fn_run_cmd within many different functions.

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

Below is the output I'm getting:

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

Desired result:

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

Upvotes: 1

Views: 509

Answers (1)

falsetru
falsetru

Reputation: 369044

First, cmd become a list, change it to become a string by unwrapping surrounding [.....]

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

list(args), storage_id, horcm_num are list. They need to be passed as arguments of strings, not lists; Use func(*...) to expand list into argument:

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

Upvotes: 2

Related Questions