[Python-Dev] avoiding accidental shadowing of top-level libraries by the main module

Fred Drake fdrake at acm.org
Tue Jul 13 15:29:52 CEST 2010


On Tue, Jul 13, 2010 at 9:00 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Making sure both __main__ and the corresponding importable name refers
> to the same module object seems reasonable.

One detail that may not have been obvious when I described the
persistent object problem; when class references are pickled, they
should be for the "real" name of the module, not __main__.  Loading
the file as __main__ and adding an alias in sys.modules simply isn't
sufficient.  Existing instances could be loaded, but new instances
would cause references to the classes defined in __main__.

To some degree, this sort of problem can be easily handled using a
"don't do that" approach, and this isn't likely to burn someone just
learning Python on the first day.  (Well, maybe in the afternoon, once
they've got the basics down.)


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
"A storm broke loose in my mind."  --Albert Einstein


More information about the Python-Dev mailing list