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!newsfeed1a.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'init': 0.07; 'none:': 0.07; '*args,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; 'wrote': 0.14; '**kwargs):': 0.16; 'bicycle': 0.16; 'cons': 0.16; 'goal,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; ':-)': 0.16; 'bit': 0.19; 'header:X-Complaints-To:1': 0.27; 'code': 0.31; 'class': 0.32; 'actual': 0.34; 'skip:_ 10': 0.34; 'could': 0.34; 'las': 0.37; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'effective': 0.61; 'judge': 0.68; 'subject.': 0.74; 'again?': 0.84; 'received:myvzw.com': 0.84; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:singleton ... again Date: Wed, 12 Feb 2014 00:48:51 -0500 (EST) Organization: news.gmane.org References: X-Gmane-NNTP-Posting-Host: 105.sub-70-208-135.myvzw.com X-Newsreader: PiaoHong Usenet NewsReaders 1.36 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1392183929 news.xs4all.nl 2864 [2001:888:2000:d::a6]:41202 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:65999 Asaf Las Wrote in message: > playing a bit with subject. > > pros and cons of this approach? did i create bicycle again? :-) > > class myclass(object): > class_instance = None > > def __new__(cls, *args, **kwargs): > if myclass.class_instance == None: > return object.__new__(cls) > return myclass.class_instance > > def __init__(self, some): > if self.__class__.class_instance == None: # init blocker > self.__class__.class_instance = self > self.member = some > > def __del__(self): > self.__class__.class_instance = None > > one_class = myclass(1) > print(id(one_class), one_class.member ) > > two_class = myclass(2) > print(id(two_class), two_class.member) > > Perhaps if you would state your actual goal, we could judge whether this code is an effective way to accomplish it. -- DaveA