Getting a callable for any value?
andrea crotti
andrea.crotti.0 at gmail.com
Wed May 29 13:55:51 EDT 2013
On 05/29/2013 06:46 PM, Croepha wrote:
> Is there anything like this in the standard library?
>
> class AnyFactory(object):
> def __init__(self, anything):
> self.product = anything
> def __call__(self):
> return self.product
> def __repr__(self):
> return "%s.%s(%r)" % (self.__class__.__module__,
> self.__class__.__name__, self.product)
>
> my use case is:
> collections.defaultdict(AnyFactory(collections.defaultdict(AnyFactory(None))))
>
I think I would scratch my head for a good half an hour if I see a
string like this, so I hope there isn't anything in the standard library
to do that :D
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130529/75e59146/attachment.html>
More information about the Python-list
mailing list