The original version no longer works in Pythonista 3. It seems that the dir function now converts the return value of __dir__ to an actual list, instead of allowing a subclass. This is the updated version:

import sys import types class DirAllTheGlobals(types.ModuleType): import __main__ def __dir__(self): return dir(type(self).__main__) # THESE LINES MUST COME LAST. # Anything past this point is executed in the context of the old # pythonista_startup module, which may already be partially # garbage-collected. new_module = DirAllTheGlobals(__name__, __doc__) vars(new_module).update(vars(sys.modules["pythonista_startup"])) sys.modules["pythonista_startup"] = new_module

This should also still work in Pythonista 2.

@omz please can you add the option to keep globals back?