morfizm (morfizm) wrote,
morfizm
morfizm

  • Mood:

Simple dynamic context-wrapper functions in Python

def wrapper(context):
    def single_argument_function(x):
        print('%s %s' % (x, context))
    return single_argument_function

a = wrapper(1)
a(5) # prints 5 1
a(6) # prints 6 1
a = wrapper(2)
a(7) # prints 7 2
a(8) # prints 8 2
Tags: in english, software development
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 7 comments