Clearing globals in CPython

Marco Buttu marco.buttu at
Wed Oct 1 18:39:20 CEST 2014

On 01/10/2014 18:00, Steven D'Aprano wrote:

> Out of curiosity, I ran:
> globals().clear()
> in the interactive interpreter. It broke much more than I expected!
> Built-ins were no longer available, and import stopped working.

Interesting... :D

> 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?

 >>> [].__class__.__module__ # It is a string...

So, I do not have any idea about how to get a module without importing 
something. Thanks for sharing :)

Marco Buttu

INAF-Osservatorio Astronomico di Cagliari
Via della Scienza n. 5, 09047 Selargius (CA)
Phone: 070 711 80 217
Email: mbuttu at

More information about the Python-list mailing list