This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients ncoghlan, terry.reedy
Date 2019-04-20.02:26:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555727197.86.0.935154304195.issue36665@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2019-04-20 02:26:37terry.reedysetrecipients: + terry.reedy, ncoghlan
2019-04-20 02:26:37terry.reedysetmessageid: <1555727197.86.0.935154304195.issue36665@roundup.psfhosted.org>
2019-04-20 02:26:37terry.reedylinkissue36665 messages
2019-04-20 02:26:37terry.reedycreate