Skip to content

Instantly share code, notes, and snippets.

@mistermocha
Last active August 29, 2015 14:08
Show Gist options
  • Save mistermocha/0f7eaf69f02afb6cfb05 to your computer and use it in GitHub Desktop.
Save mistermocha/0f7eaf69f02afb6cfb05 to your computer and use it in GitHub Desktop.
class BigStorageClass(object):
'''Class that will represent a large data blob that contains lots of smaller child objects'''
def lookup_something(self, **kwargs):
some_data = self.do_something_with(kwargs)
return some_data
class SmallChildObject(object):
'''Instantiation of this class needs to look up something in an instance of the BigStorageClass. Clearly,
I don't want to make BigStorageClass a child of SmallChildObject. Is there a way to pass in the *name* of
the BigStorageClass instance as a string and get the instance?'''
def __init__(self, ref_to_storage)
self.look_in_storage_class(ref_to_storage)
def look_in_storage_class(self, classname):
storage_class = get_instance_by(classname)
return storage_class(...)
bigdata = BigStorageClass(...)
''' do some stuff to put lots of data in bigdata '''
smallobj = SmallChildObject(self, 'bigdata')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment