Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class FirstComponent(object):
def __init__(self, parent):
object.__init__()
parent.someFunc = self.someFunc
def someFunc(self):
return 42
class GameObject(object):
def __init__(self):
object.__init__()
self._components = []
component = FirstComponent(self)
self._components.append(component)
if __name__ == "__main__":
go = GameObject()
if has_attr(go, "someFunc"):
go.someFunc()
# or
try:
go.someFunc()
except:
pass # nothing, it's just not implemented for this object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment