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

Fred Drake fdrake at acm.org
Tue Jul 13 23:34:58 CEST 2010


On Tue, Jul 13, 2010 at 5:02 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> Fred's point about the practice of changing __name__ in the main
> module corrupting generated pickles is one I hadn't thought of before
> though.

Not sure about changing __name__ anywhere... I don't do that.

When an "application" is defined more by operations on persistent data
then what top-level script is run, we (Zope Corp.) often have many
different __main__s that run with the same database; there's generally
not any point in thinking of the script as a module at all; the fact
that it's available as sys.modules['__main__'] isn't important.

We generally avoid the problem by applying the don't-do-that rule.
Our actual scripts are always generated, and don't live in
module-space.  Understanding what not to do is an important aspect of
teaching, though.


  -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