Python Forum

Full Version: Multi-Dimm Array or Class?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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