Created
May 12, 2015 17:16
-
-
Save directionless/cc561241acfeee98020d to your computer and use it in GitHub Desktop.
Python describing functions
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 TestClass(object): | |
STRINGS={} | |
STRINGS["func1"] = lambda t: "func1 {0}".format(t) | |
def func1(self, t): | |
return "I did func1" | |
STRINGS["func2"] = lambda t: "func2 {0}".format(t) | |
def func2(self, t): | |
return "I did func2" | |
foo = TestClass() | |
print getattr(foo, "func1")("hello") | |
print foo.STRINGS.get("func1", lambda t: "")("hello") | |
print foo.STRINGS.get("undescribed", lambda t: "")("hello") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment