Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'cpython': 0.05; 'sys': 0.07; 'exception,': 0.09; 'executes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'throws': 0.09; 'python': 0.11; 'jan': 0.12; "'__doc__',": 0.16; '2:28': 0.16; 'builtins': 0.16; 'clear.': 0.16; 'clears': 0.16; 'idle,': 0.16; 'itself,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'sys.modules': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'gives': 0.31; 'code': 0.31; "skip:' 10": 0.31; '"",': 0.31; '>>>>': 0.31; 'apparently': 0.31; 'subject:what': 0.31; 'file': 0.32; '(most': 0.33; 'subject:with': 0.35; 'there': 0.35; 'idle': 0.36; 'module.': 0.36; 'wrong': 0.37; 'clear': 0.37; 'process,': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'lost': 0.61; 'more': 0.64; 'literally.': 0.84; 'received:fios.verizon.net': 0.84; '2013,': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: what is wrong with d.clear()? Date: Mon, 22 Dec 2014 03:58:02 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-108-16-203-145.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 In-Reply-To: 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1419238703 news.xs4all.nl 2946 [2001:888:2000:d::a6]:47973 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:82761 On 12/21/2014 2:28 AM, shawool wrote: > where am i going wrong ? You clear sys.modules, which apparently CPython uses in its normal function. > Python 3.2.5 (default, Oct 2 2013, 22:58:11) >>>> d = {} >>>> import sys >>>> d = sys.modules >>>> type(d) > >>>> dir(d) > ['__class__', '__contains__', '__delattr__', '__delitem__', '__doc__', > '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', > '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', > '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', > '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', > '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', > 'pop', 'popitem', 'setdefault', 'update', 'values'] dir(d) is the contents of d.__dict__, not d itself, so the above is not what you clear. Just type d to see what is cleared. >>>> d.clear() > Traceback (most recent call last):dir( > File "", line 1, in There is no code line because the exception in in C code. 3.4.2 gives more info: RuntimeError: lost builtins module. Do upgrade if you can. In Idle, this executes 'ok', without an exception, because it clears sys.modules in the user process, not the Idle process. >>>> d > Traceback (most recent call last): > File "", line 1, in However, this throws the user process into a loop, literally. -- Terry Jan Reedy