About Callable Function Arguments

Using callable() you can allow a function to accept either values or functions that return values. Here is an example of the pattern:

1
2
3
4
5
6
from datetime import datetime

def do_something(timestamp=datetime.now):
    if callable(timestamp):
        timestamp = timestamp()
    print(timestamp)

Tips and Tricks Programming Python 3