David Abrams wrote: >> If anyone can think of any really elegant hacks that are naturally >> expressed by partial function application I'd like to see them > > > >There are millions, but AFAICT they're all more natural with lambda, >so... > > "I agree that lambda is usually good enough, just not > always." > >Examples, please? > > Well, you can use partial to special-case classes as shorthand object factories. So: C = partial(Canvas,my_window,width=100,height=100,bg='white') ...gives you a callable C that is a factory for Tkinter Canvases parented to my_window, 100 pixels on a side, and with a white background. How this differs from lambda is that you can override keyword parameters from the supplied defaults: c1 = C() c2 = C(width=200) c3 = C(bg='red') > "And I want the possibility of useful introspection and > subclassing" > >Can you elaborate on that, please? > > > You could maybe sub-class partial to override __call__ , in case you want to do anything fancy like pre-supplying arguments at arbitrary positions. You can inspect or indeed change C.fn, C.kw or C.args in the example above. I'm not speculating on why you might want to, but there's nothing stopping you. :) Peter Harris
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4