[Tutor] 'module' object has no attribute (setting a class attribute)

Tim Johnson tim042849 at gmail.com
Sat Oct 16 17:35:28 CEST 2010

* Dave Angel <davea at ieee.org> [101016 03:45]:
> 1) The code is correct.  But it'd be much clearer if you followed  
> conventions and named your class with a leading uppercase.  So the  
> module would be called tmpl, and the class would be called Tmpl.
 <blush> I didn't know there was such a convention. Serves me right
 for being self-taught and self-employed </blush>
> 2) For the general case, this error is about fetching attributes from  
> arbitrary objects.  Such an object is not always bound to a single name,  
> so it reports the object's type, rather than its name.  In this  
> particular case, a module has a unique name, so the message could have  
> been more helpful.  But it's not clear how the error display logic could  
> have readily known that.
  Ah! Understood.

> Two things could help you figure it for yourself more quickly.  a) On  
> the left side of such an assignment, this error can only refer to  
> attributes other than the last, since the last one is being created  
> here, and it wouldn't matter if it already existed.  b) You could  
> refactor the line, and see where the error message moves to.  Let's try  
> that:
  Good trick.
> a = kbLib.templatepath
> tmpl.Ttmpl.templatepath = a
> If the line that now gets the error had still been confusing, you could  
> try to refactor that in turn.
tim at johnsons-web.com or akwebsoft.com

More information about the Tutor mailing list