Created
August 31, 2018 12:06
-
-
Save sebastianw/43341df6c7c4deaa189e26da01a1c0ca to your computer and use it in GitHub Desktop.
A python object which forwards all get/set requests (and functions) to a list of (identical) child objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObjectList(object): | |
def __init__(self, child_objects): | |
self.child_objects = child_objects | |
def __getattr__(self, name): | |
def looper(*args, **kwargs): | |
for obj in self.child_objects: | |
attr = getattr(obj, name) | |
attr(*args, **kwargs) | |
return looper | |
def __setattr__(self, key, value): | |
if key in ['child_objects']: | |
super(ObjectList,self).__setattr__(key,value) | |
else: | |
for obj in self.child_objects: | |
setattr(obj, key, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment