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.

>From your previous message, I read that modules are treated just like classes 
>or any other attribute - did I misinterpret your advice?

Thanks,

Jan
-- 
I was gratified to be able to answer promptly, and I did. I said I didn't know. 
- Mark Twain
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to