Hi, Jan Eden wrote on 22.11.2005:
>Hi, > >Kent Johnson wrote on 20.11.2005: >> >>Use getattr() to access attributes by name. SiteA is an attribute >>of Templates and Page is an attribute of SiteA so you can get use >>getattr() twice to get what you want: >> >>site = getattr(Templates, self.site_name) self.template = >>getattr(site, self.template_type) >> > >Unfortunately, this does not seem to work if Templates is a package, >not a module. Python complains: > >AttributeError: 'module' object has no attribute 'SiteA' > args = ("'module' object has no attribute 'SiteA'",) > >even though there is a module SiteA within package Templates. When >manually importing SiteA from Templates, everything is good. > Found a solution: import Templates #... def GetTemplates(self): __import__('Templates.', globals(), locals(), [self.identifier]) site = getattr(Templates, self.identifier) self.template = getattr(site, self.template_type) works. Thanks, Jan -- He who would give up a little liberty in return for a little security deserves neither liberty nor security. - Benjamin Franklin _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor