Created
May 26, 2012 07:49
-
-
Save cjhanks/2792832 to your computer and use it in GitHub Desktop.
Nested Class
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 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