I am a small-time user of Python, I write the occasional script when it helps with work. I think using classes for some of the data structures that I end up dealing with would potentially be cleaner and easier. I get the idea of classes but I’m not sure how to logically approach it. For example:
We run a wireless system, there are lots of access points serving wireless clients and sometimes it is useful to get info about all of them (the info is actually retrieved via API from a central controller, not by talking to the access points themselves), so it seems like having an access point class would make sense. Typically in any script I will end up with a list of access point MAC addresses. Ideally what I want to be able to do from a script is to create an access point object by passing a MAC address, and for the access point object to come back with all its attributes populated (this would involve an API call to the controller to get the info). So basically my question is should this population of the attr values be done in/by the class itself (as part of init?), or should I have a separate function which takes the empty access point object and does the API call and assigns the values to the access point object? I’m thinking probably the latter, but if the former is possible maybe it would be a nice way to do it? I’m just wondering what peoples’ thoughts are.