Skip to content

Instantly share code, notes, and snippets.

@elleryq
Created October 18, 2013 07:55
Show Gist options
  • Save elleryq/7037985 to your computer and use it in GitHub Desktop.
Save elleryq/7037985 to your computer and use it in GitHub Desktop.
Assign function as function's method.
def foo(a, b, c):
print(a, b, c)
def get_n():
print("get_n()")
def put_n():
print("put_n()")
foo.get_n = get_n
foo.put_n = put_n
foo.get_n()
foo(1, 2, 3)
foo.put_n()
# 結果:
# get_n()
# (1, 2, 3)
# put_n()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment