partial allow you to define a partial (doh!) application of a function to arguments. My common use (currently) is for re.sub
>>> from functools import partial
>>> import re
>>> remove_prefix = partial(re.compile("prefix: ").sub, "")
>>> remove_prefix("prefix: hello")
'hello'
>>> remove_prefix("hello")
'hello'
>>>
No comments:
Post a Comment