Lazy imports (was Re: module naming)

Greg McFarlane gregm at iname.com
Thu Apr 20 16:47:52 CEST 2000


On 18 Apr, Peter Funk wrote:
> You could try to adopt the lazy loader concept implemented in 
> the Pmw package.  ...


I think there is a bug in your code.  Several lines have the wrong
indentation.  The following:
>         for name in dict.keys():
>             self.__dict__[name] = {}
>             d = {}
>             execfile(os.path.join(self._path, _EXP_DEF), d)
>             for k,v in d.items():
>                 if dict.has_key(k):
>                     if type(v) == types.TupleType:
>                         for item in v:
>                             ## modpath = self._package + item
>                             modpath = item
>                             dict[k][item] = modpath
>                     elif type(v) == types.DictionaryType:
>                         for k1, v1 in v.items():
>                             ## modpath = '_'+self._package +'.'+ v1
>                             modpath = v1
>                             dict[k][k1] = modpath

should be:
>         for name in dict.keys():
>             self.__dict__[name] = {}
>         d = {}
>         execfile(os.path.join(self._path, _EXP_DEF), d)
>         for k,v in d.items():
>             if dict.has_key(k):
>                 if type(v) == types.TupleType:
>                     for item in v:
>                         ## modpath = self._package + item
>                         modpath = item
>                         dict[k][item] = modpath
>                 elif type(v) == types.DictionaryType:
>                     for k1, v1 in v.items():
>                         ## modpath = '_'+self._package +'.'+ v1
>                         modpath = v1
>                         dict[k][k1] = modpath

-- 
Greg McFarlane     INMS Telstra Australia     gregm at iname.com




More information about the Python-list mailing list