Skip to content

Instantly share code, notes, and snippets.

@chiiph
Created May 3, 2013 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chiiph/5506433 to your computer and use it in GitHub Desktop.
Save chiiph/5506433 to your computer and use it in GitHub Desktop.
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