TypeError: 'module object is not callable'

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Mon Sep 3 07:26:54 EDT 2007


christophertidy at hotmail.com a écrit :
> Thank you for your help that seems to have done the trick.
> You are correct Diez B. Roggisch that I come from a java background!
> 
> I have a new tiny problem I can't understand either.
> Withing Step.py I have the following method
> 
> def isCompleted(self):
>     "Check whether data step has been processed"
>     return self.isCompleted

Java background, indeed !-)

In Python, everything (including functions, methods, modules, classes 
etc) is an object, and methods are just attributes like every others - 
ie, there's no separate namespaces for methods. So when you set an 
instance attribute 'isCompleted', it shadows the class attribute by the 
same name.

The obvious solution is to give attributes different names. The perhaps 
less obvious but much more pythonic solution is to get get rid of the 
getter if all it does is returning the attribute. I know this sounds 
strange when coming from Java, but there's no problem doing so - Python 
has support for computed attributes (aka properties), so you can always 
replace a plain attribute by a computed one latter if you need to do so, 
this won't impact the client code.

HTH



More information about the Python-list mailing list