On Sep 16, 10:29 pm, Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Wed, 17 Sep 2008 13:52:13 +1200, greg wrote: > > Arnaud Delobelle wrote: > > >> Or: > > >> import ModuleName as this_module > > > Or: > > > this_module = __import__(__name__) > > > then you don't have to change anything. > > I like that solution! And it works regardless of whether the module > holding it is imported, or is being executed from the commandline.
It doesn't work if the module is part of a package. For that could use sys.modules[__name__] or write a separate function to return the appropriate nested module of __name__. Neither method is foolproof I don't think. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list