Terry J. Reedy <tjre...@udel.edu> added the comment:
To me, the failure of dir() in message 1 is surprising and possibly a bug. I always though of a module globals = locals = dict() instance as continuous across statements, whether in batch or interactive move. In batch mode import sys mod = sys.modules[__name__] sys.modules[__name__] print(dir()) works. Adding '-i' to the command line is supposed to allow one to enter interactive statements to be executed in the same namespace. In IDLE's Shell, dir() in msg 1 executes normally. This is because idlelib.run.Executive() initializes the instance by caching globals(). self.locals = __main__.__dict__ Then self.runcode(self, code) executes user statements with exec(code, self.locals) With exec in the old statement form of 'exec code in self.locals', this pair predates the first patch git has access to, on 5/26/2002 (GvR, committed by Chui Tey). Could and should, python do similarly, and keep a reference to the module namespace? What did Python do in 2002? What do other implementations and simulated Shells do now? ---------- nosy: +terry.reedy _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36665> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com