Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.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; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.04; 'importerror:': 0.07; 'nicely': 0.07; 'python3': 0.07; 'exit': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'restart': 0.09; 'python': 0.11; 'language.': 0.14; 'from...': 0.16; 'peters': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:Clearing': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'header:X-Complaints- To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tim': 0.29; '"",': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'linux': 0.33; '(most': 0.33; 'but': 0.35; 'done': 0.36; 'skip:o 20': 0.38; 'easiest': 0.38; 'skip:. 20': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'our': 0.64; 'more': 0.64; 'charset:windows-1252': 0.65; 'apart': 0.72; '2014,': 0.84; 'otten': 0.84; 'received:2': 0.84; 'us?': 0.84; 'zen': 0.84; 'recover': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Clearing globals in CPython Date: Thu, 02 Oct 2014 09:30:20 +0100 References: <542c2527$0$13013$c3e8da3$5496439d@news.astraweb.com> <542d08cf$0$13006$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-196-203.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.2 In-Reply-To: <542d08cf$0$13006$c3e8da3$5496439d@news.astraweb.com> 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: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1412238648 news.xs4all.nl 2829 [2001:888:2000:d::a6]:49397 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78587 On 02/10/2014 09:11, Steven D'Aprano wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: > >>> Obviously the easiest way to recover is to exit the current session and >>> restart it, but as a challenge, can we recover from this state? >> >> $ python3 >> Python 3.4.0 (default, Apr 11 2014, 13:05:11) >> [GCC 4.8.2] on linux >> Type "help", "copyright", "credits" or "license" for more information. >>>>> globals().clear() >>>>> import that >> Traceback (most recent call last): >> File "", line 1, in >> ImportError: __import__ not found >>>>> object = 1 .__class__.__bases__[0] >>>>> Quitter = [c for c in object.__subclasses__() if c.__name__ == >> "Quitter"][0] >>>>> __builtins__ = Quitter.__call__.__globals__["__builtins__"] >>>>> import this >> The Zen of Python, by Tim Peters > > Nicely done! > Other than the Zen of Python what has Tim Peters ever done for us? Apart from... -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence