On Mon, Dec 26, 2005 at 17:41 +0000, Paolino wrote: > I'd like to catch AttributeError on the module level,so that I can > declare default bindings for useds defore definition.How is this to be > done?Thanks for help.
It cannot be done directly but with a small hack. This is the idea: import sys class A: def __getattr__(self,name): if name[:1] != '_': return name raise AttributeError(name) sys.modules['a'] = A() import a print a.helloworld # will print "helloworld" Note, that subsequently you can "import a" also from other modules because the import statement consults sys.modules. This is all a bit bothersome and thus it's often easier to just do "from somemod import a" directly and forget about the above magic. cheers, holger -- http://mail.python.org/mailman/listinfo/python-list