Skip to content

Instantly share code, notes, and snippets.

@fvosberg
Created July 21, 2017 05:13
Show Gist options
  • Save fvosberg/f822f3aa0f2fd9629992aa673331c42f to your computer and use it in GitHub Desktop.
Save fvosberg/f822f3aa0f2fd9629992aa673331c42f to your computer and use it in GitHub Desktop.
Trying to find a nice and clean solution in python with currying
#!/usr/local/bin/python3.6
def init_hr():
number = 0
def inner():
nonlocal number
number += 1
print("============================================================================")
print("============================== UEBUNG ", number, "===================================")
print("============================================================================")
print()
print()
return inner
hr = init_hr()
hr()
hr()
hr()
# Kind of decorator, although it changes the interface of the function
def call_with_sequence_of_numbers(func):
number = 0
def wrapper():
nonlocal number
number += 1
func(number)
return wrapper
@call_with_sequence_of_numbers
def print_headline(number):
print("============================================================================")
print("============================== UEBUNG ", number, "===================================")
print("============================================================================")
print()
print()
print_headline()
print_headline()
print_headline()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment