Skip to content

Instantly share code, notes, and snippets.

@cjhanks
Created May 26, 2012 07:49
Show Gist options
  • Save cjhanks/2792832 to your computer and use it in GitHub Desktop.
Save cjhanks/2792832 to your computer and use it in GitHub Desktop.
Nested Class
class SomeParentClass:
""" @class SomeParentClass
An arbitrary class.
"""
def __init__(self):
pass
def some_member_function(self, var):
""" This function takes in a variable and places it into a nested
class which can be callable
"""
class nested_class:
def __init__(self, var):
self.__var = var
def var(self):
return self.__var
return nested_class(var)
if __name__ == '__main__':
parent = SomeParentClass()
nested = parent.some_member_function('words')
# See? Now this variable is available here by name!
print(nested.var())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment