Python Forum
Populating Array2 from Array1
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Populating Array2 from Array1
#1
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
Reply
#2
Persistence!

elif (current_line[0] == "username"):
username_list.append(current_line[1])

No need to set the list, simply append it!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Populating an array dynamically zxcv101 1 1,106 May-17-2022, 11:24 AM
Last Post: deanhystad
  Populating a timetable with subjects brittocj 1 1,778 May-02-2019, 07:00 AM
Last Post: buran
  Populating a list with divisors RedSkeleton007 1 2,148 Aug-21-2018, 12:52 AM
Last Post: Larz60+
  populating csv and searching the file mepyyeti 1 2,925 Apr-26-2018, 03:02 AM
Last Post: woooee
  for loop and list populating mepyyeti 3 3,408 Apr-12-2018, 03:06 AM
Last Post: buran
  Importing file in dataframe and populating missing column name vvv 1 3,408 Feb-26-2017, 02:32 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020