Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multi-Dimm Array or Class?
#1
I'm working on a config converter for firewalls. (Take ASA config, make it a Palo Alto config, or a Juniper config, etc).

What I'm actually trying to do is store the following type of data

rule1, src-intf, src-zone, dst-intf, dst-zone, allowed, protocol, port
rule2, src-intf, src-zone, dst-intf, dst-zone, allowed, protocol, port
rule3, src-intf, src-zone, dst-intf, dst-zone, allowed, protocol, port
rule4, src-intf, src-zone, dst-intf, dst-zone, allowed, protocol, port

I'm wonder when the decision point is to use a class, or simply use a multi-dimm array?
Would I do something like?:
class SecurityPolicies:
  def __init__(self):
    self.description = description
    self.src_intf = src_intf
	self.src_zone = src_zone
	self.dst_intf = dst_intf
	self.dst_zone = dst_zone
	self.pmt_deny = allowed

original_lines = original_file.readlines()
for counter in range(len(original_lines)):	
Policy[counter] = SecurityPolicies
** note syntax may not be 100% accurate

or is it simply easier to just use multi-dimm arrays?

Thanks for advice in advance
PappaBear
Reply
#2
it depends - would you have methods, extra attributes, would you make change in values, etc.
if it will be just data structure as shown in your example you can consider using the namedtuple from collections or dict, etc.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
ahhh, would never have known to look for that -- namedtuple is exactly what I'm looking for!!
I felt like a class was "too much" and an array wasn't enough...this should do the trick!

Huge thanks,
PappaBear
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multi-class iterator Pedroski55 2 2,378 Jan-02-2021, 12:29 AM
Last Post: Pedroski55
  Applying Multi-Class Classification instead of binary classification alex80 1 1,500 Sep-18-2020, 07:39 AM
Last Post: alex80
  class random var write to array storzo 5 2,883 Aug-02-2019, 03:26 PM
Last Post: storzo
  multi-dimm array -- dynamic PappaBear 3 2,555 May-03-2019, 03:47 AM
Last Post: buran
  Best construct? Array, class, other? PappaBear 1 2,967 May-10-2017, 06:02 PM
Last Post: nilamo
  What work faster and take less memory array or class? Kamilbek 1 3,130 Apr-20-2017, 05:32 PM
Last Post: Larz60+
  Fast method of searching a string in a multi-dimension array? draems 6 5,947 Feb-20-2017, 01:02 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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