Showing content from http://mail.python.org/pipermail/python-dev/attachments/20060220/2f99b73a/attachment.htm below:
<br><br><div><span class="gmail_quote">On 2/20/06, <b class="gmail_sendername">Raymond Hettinger</b> <<a href="mailto:raymond.hettinger@verizon.net" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
raymond.hettinger@verizon.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>An alternative is to have two possible attributes:<br> d.default_factory = list<br>or<br> d.default_value = 0<br>with an exception being raised when both are defined (the test is done when the<br>attribute is created, not when the lookup is performed).
<br><br>
</blockquote></div><br>Why not have the factory function take the key
being looked up as an argument? Seems like there would be uses to
customize the default based on the key. It also forces you to
handle list factory functions and constant factory functions (amongst
others) to be handled the same way:<br>
<br>
d.default_factory = lambda k : list()<br>
d.default_factory = lambda k : 0<br>
<br>
Dan Gass<br>
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