I am generating a list of computers attached to a server. For each computer I gather a list of properties. I am new to Python and programming and am finding my solution rather clunky.
I was doing this with lists. I have a master list: computer_list and each computer is another list, with attributes such as status, date, profile, etc.
computer_list = [cname1, cname2, cname3]
cname1 = ['online', '1/1/2012', 'desktop']
The downsides of this method are becoming obvious the more I work and change this program. I’m hoping for something more intuitive. I looked into dictionaries, but that solution seems almost as convoluted as mine. The list within a list is workable but not readable once I start iterating and assigning. I am sure there is a better way.
Make each computer an object:
Then store these in a dictionary or list.
Now when you iterate over them, it’s straightforward:
You can also define
__str__()on the class to define how they are displayed, and so on.