Skip to content

Instantly share code, notes, and snippets.

@brezniczky
Last active January 3, 2020 15:17
Show Gist options
  • Save brezniczky/f2b9efb6d1f76786ee8a048b8225c5b1 to your computer and use it in GitHub Desktop.
Save brezniczky/f2b9efb6d1f76786ee8a048b8225c5b1 to your computer and use it in GitHub Desktop.
Demonstrates that Python's partial() allows for 'overriding' the already frozen parameters
""" Partial's frozen arguments are not 'as frozen' as I would have thought
at first.
"""
from functools import partial
f = partial(int, base=2)
# results in 9 - great!
print(f("1001"))
# 1. executes, no warning, no exception :(
# 2. results in 28 :S
print(f("1001", base=3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment