Clearing globals in CPython
breamoreboy at yahoo.co.uk
Thu Oct 2 10:30:20 CEST 2014
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.
>>>>> import that
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> ImportError: __import__ not found
>>>>> object = 1 .__class__.__bases__
>>>>> Quitter = [c for c in object.__subclasses__() if c.__name__ ==
>>>>> __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?
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
More information about the Python-list