other python ideas

Rainer Deyke root at rainerdeyke.com
Mon Apr 9 12:25:45 EDT 2001


"Jeff Petkau" <jpet at eskimo.com> wrote in message
news:CXaA6.1200$fP5.449625 at paloalto-snr1.gtei.net...
> For avoiding import statements, you could write something
> like this:
>
>     class ModuleGetter:
>         def __getattr__(self,name):
>             if name.startswith('__'):
>                 raise AttributeError
>                     return __import__(name)
>     module = ModuleGetter()

This won't work if the module you want is in another package.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list