Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dynamically create a list
#1
greetings all,
I think my question is a simple one. At the base of it, I am trying to get python to generate an empty list based on the value in a specific point of a line of text (config vdom root edit root) <<<< so I would want to make an empty list on position 5 in this line which is root

So I have a text file and it could be 500 lines or 5000 lines. I am trying to loop through it and make some choices but I am having a problem figuring out how to generate an empty list based on some values found.

A portion of the text file is below and at the beginning of the text file there are always lines that start with 'config vdom root edit XXXXX' where XXXXX is the name I am looking to get turned in to a List(So Object Position 4 after the line is split).

Once the list is created and empty then I would loop through the file and I will split each line where on the spaces

Then for each line that begins with 'config firewall address' it would look at splitline[3] which in the first line below would be untrust and would be the name of one of the empty lists created, and I would append the value of splitline[5] which in the first line is objectname1 into the list. Note that there could be as little as 2 'config vdom root edit XXXXX' entries or as many as say 20 and they can have any name. See below the output for what I am trying to achieve which is I will then loop through each of the lists and take some action.

config vdom root edit root
config vdom root edit untrust
config vdom root edit trust
config vdom root edit proxy
......more lines throughout the file........
config firewall address untrust edit objectname1 set subnet 10.1.1.0 255.255.255.224
config firewall address untrust edit objectname2 set subnet 10.2.2.0 255.255.255.224
config firewall address untrust edit objectname3 set subnet 10.3.3.0 255.255.255.224
config firewall address untrust edit objectname4 set subnet 10.4.4.4 255.255.255.255
config firewall address trust edit objectname1 set subnet 10.1.1.0 255.255.255.224
config firewall address trust edit objectname2 set subnet 10.2.2.0 255.255.255.224
config firewall address trust edit objectname3 set subnet 10.3.3.0 255.255.255.224
config firewall address trust edit objectname4 set subnet 10.4.4.4 255.255.255.255
config firewall address root edit objectname11 set subnet 10.100.1.0 255.255.255.224
config firewall address root edit objectname12 set subnet 10.102.2.0 255.255.255.224
config firewall address root edit objectname13 set subnet 10.103.3.0 255.255.255.224
config firewall address root edit objectname14 set subnet 10.4.4.4 255.255.255.255
config firewall address proxy edit objectname31 set subnet 192.168.1.0 255.255.255.224
config firewall address proxy edit objectname32 set subnet 192.168.2.0 255.255.255.224
config firewall address proxy edit objectname33 set subnet 192.168.3.0 255.255.255.224
config firewall address proxy edit objectname34 set subnet 192.168.4.4 255.255.255.255

So when it runs through the file and before I take an action on the lists I would hope that the lists contained the following:

root = [objectname11, objectname12, objectname13, objectname14]
untrust = [objectname1, objectname2, objectname3, objectname4]
trust = [objectname1, objectname2, objectname3, objectname4]
proxy = [objectname31, objectname32, objectname33, objectname34]


Any assistance would be greatly appreicated. If I am potentially taking the wrong approach I am willing to adjust my methods as well.
THANKS
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Delete strings from a list to create a new only number list Dvdscot 8 1,511 May-01-2023, 09:06 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,505 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  how to easily create a list of already existing item CompleteNewb 15 3,526 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Create SQLite columns from a list or tuple? snakes 6 8,660 May-04-2021, 12:06 PM
Last Post: snakes
  Create variable and list dynamically quest_ 12 4,384 Jan-26-2021, 07:14 PM
Last Post: quest_
  How to create a linked list and call it? loves 12 4,484 Nov-22-2020, 03:50 PM
Last Post: loves
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 2,030 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  How to define a function to create a resorted list? sparkt 6 2,809 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Create a program that PING a list of IPs skaailet 7 6,314 Mar-26-2020, 10:46 PM
Last Post: snippsat
  Create a list of co-ordinates from Mouse press events Jagruthi 0 1,474 Mar-12-2020, 08:46 AM
Last Post: Jagruthi

Forum Jump:

User Panel Messages

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