Skip to content

Instantly share code, notes, and snippets.

@directionless
Created May 12, 2015 17:16
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 directionless/cc561241acfeee98020d to your computer and use it in GitHub Desktop.
Save directionless/cc561241acfeee98020d to your computer and use it in GitHub Desktop.
Python describing functions
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