Aug-22-2018, 12:20 AM
High level -- working on converting vendor-A network switch config to Vendor-B syntax
I am reading a config file, of which I have the current line; if the current line starts with "username", then I want to append the current username at current_line[1] to an existing array username_list[]
There's actually a bunch of elifs before my username elif, all working fine. I can't seem to figure out the correct way to populate (append) one array with the value of the current variable.
username_list=[]
broken code snippet
===============
if (current_line[0] == "hostname"):
hostname = current_line[1]
elif (current_line[0] == "username"):
username_list = username_list.append[str(current_line[1])]
TypeError: 'builtin_function_or_method' object is not subscriptable
I've also tried
===============
elif (current_line[0] == "username"):
username_list = username_list+current_line[1]
TypeError: can only concatenate list (not "str") to list
at a loss; appreciate some direction
thanks,
PappaBear
I am reading a config file, of which I have the current line; if the current line starts with "username", then I want to append the current username at current_line[1] to an existing array username_list[]
There's actually a bunch of elifs before my username elif, all working fine. I can't seem to figure out the correct way to populate (append) one array with the value of the current variable.
username_list=[]
broken code snippet
===============
if (current_line[0] == "hostname"):
hostname = current_line[1]
elif (current_line[0] == "username"):
username_list = username_list.append[str(current_line[1])]
TypeError: 'builtin_function_or_method' object is not subscriptable
I've also tried
===============
elif (current_line[0] == "username"):
username_list = username_list+current_line[1]
TypeError: can only concatenate list (not "str") to list
at a loss; appreciate some direction
thanks,
PappaBear