using del() to 'unimport'

TeaAndBikkie teaandbikkie at aol.com
Sun Nov 24 10:03:38 EST 2002


>From: donnal at donnal.net  (Donnal Walter)
>
>When the the following module is imported, I want only 'MyClass' (NOT
>'Useful' and 'Mixin1') to be publicly accessible.
>
>======= mymodule.py ==================
>from utilities import Useful, Mixin1
>
>class MyClass(Useful, Mixin1): pass
>
>del(Useful)
>del(Mixin1)
>======================================

One alternative is not to import the names in the first place, eg.

import utilities
class MyClass(utilities.Useful, utilities.Mixin1): pass

Then you would only have "utilites" in the main namespace.

--Misha




More information about the Python-list mailing list