Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'subject:Getting': 0.07; 'string': 0.09; 'library?': 0.09; 'def': 0.12; 'scratch': 0.16; 'wrote:': 0.18; 'library': 0.18; 'header:User-Agent:1': 0.23; 'skip:c 70': 0.24; 'header:In-Reply-To:1': 0.27; 'skip:( 20': 0.30; 'class': 0.32; 'skip:_ 10': 0.34; 'received:google.com': 0.35; 'there': 0.35; 'subject:?': 0.36; 'half': 0.37; 'message- id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'hope': 0.61; 'hour': 0.70; 'received:192.168.15': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=qZq7STnq33TfTgbGlDMA43ed6/dUSfTSxPPipSHPlY0=; b=DmWOQSD5iOUFiqR5B4OivKA6vcrYOJys1rOWAMzB6XvHuftVHruLrrdwH9ytcuuIlT JDtenBYbkOvsZAnRMi7GpT/rqvp0D7qta7IytUPzPYtz40teCckduqWVuUaexz1BWue9 rlFWu7ClfeRfwnrLyXT87LQplDLQHosGNYYi+5hkfVkrwbsf2OrDWwD2XYP/TSHnrxXd 4UrfY5HHO09NfD9xL/wnsJj6qzWxTRMtRELln1wXAf4afWZTH+/FnH+nzQuPLJ40eAur 11n5wKcG0S7v+YG1VhJcUsDO5bdVvFrtKNNr4/hcFxQO52NOHSLBBew/49972OiyWh2T 878Q== X-Received: by 10.194.77.66 with SMTP id q2mr2084867wjw.34.1369850152921; Wed, 29 May 2013 10:55:52 -0700 (PDT) Date: Wed, 29 May 2013 18:55:51 +0100 From: andrea crotti User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130514 Thunderbird/17.0.6 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Getting a callable for any value? References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------000402020901030900000708" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 75 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369850161 news.xs4all.nl 15899 [2001:888:2000:d::a6]:59047 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46398 This is a multi-part message in MIME format. --------------000402020901030900000708 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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 --------------000402020901030900000708 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit
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
--------------000402020901030900000708--