TypeError: 'module object is not callable'

Diez B. Roggisch deets at nospam.web.de
Mon Sep 3 12:43:51 EDT 2007


 christophertidy at hotmail.com wrote:

> 
>>
>> The others spottet the error I missed. But I can offer something else:
>>
>> http://dirtsimple.org/2004/12/python-is-not-java.html
>>
>> It's a worthy read for someone coming from Java, needing time to adjust.
>>
>> Diez- Hide quoted text -
>>
>> - Show quoted text -
> 
> That deffinately was a useful read, thanks.
> Thankyou to everyone who sorted these problems for me, I have
> progressed very well
> with this python program throughout the day now.
> 
> I have another little question before I finish today:
> I am currently struggling to use a global variable in my static
> functions. I'll explain further
> 
> Within my main.py file I have
> 
> class Main(object):
>     stepStore = StepStore()
> 
>     @staticmethod
>     def createDepSteps():
>         ....
>         stepStore.addStep([bol7, pre5])
>         .......
> 
>     @staticmethod
>     def processSteps():
>         for step in stepStore.stepList[:]:
>         ......
> 
> Main.createDepSteps()
> Main.processSteps()
> 
> 
> Trying this approach I am getting a error saying with the
> processSteps() method, stepStore is undefined
> To solve this problem I am currently passing in the processSteps()
> parameter a stepStore instance created within createDepSteps()
> but there is surely a way stepStore can be a global attribute which
> can be accessed from both methods?
> Any help would be much appreciated again

You are deeeeep down in javaland again. first of all, with the exception of
factory methods, staticmethods or classmethods usually aren't needed. In
Python, you can define functions directly.

So move the above methods "toplevel", aka out of the class-context. and just
make stepStore a module-global variable.

Then things should work. 

The distinction between staticmethod and classmethod is, that staticmethod
is a "pure" method, something unknown in Java.

the classmethod OTOH is a method that gets the class as first argument
(instead of the instance, as in an instance-method):

class Foo(object):
   @classmethod
   def bar(cls):
       print cls

However: get rid of unnecessary classes. Java is severely limited regarding
the definition of "pure" code, the permanently needed class-context for
e.g. a main-method is absurd - to say the least.

Diez



More information about the Python-list mailing list