Take the 2-minute tour ×

I've been trying to practice testing my modules by adding

if __name__ == '__main__':

to the end of the module. The idea is to run the module as a script, and get an output and able to import it from another script or an interactive python session.

I'm using Python 2.6.6

here's the whole code

class Prac:
    This module is a practice in creating a main within a module.

    def Fun(self):
        print "testing function call"

if __name__ == ' __main__':

Thanks ! wbg

share|improve this question
thanks Ignacio....duh...forgot to instantiate the object. Will try again and post –  wbg Oct 2 '11 at 3:24
what exactly is the qeustion this time? –  Foo Bah Oct 2 '11 at 3:47
Ok, it looks like you have working code... did you have a question to go with that? –  Jeff Mercado Oct 2 '11 at 3:54
I was confusing import of the file containing the class object and the obj themselves...Now I can get good output from interactive python, but the main is not working calling from bash $. –  wbg Oct 2 '11 at 4:01
There seems to be more missing from this than just the question itself. You go on to talk about issues you were having in the interactive session with the TypeError when trying to call the module as a callable. What is your entire process that you are leaving out of this post? –  jdi Oct 2 '11 at 5:13
show 1 more comment

1 Answer

That isn't a function, it's a method. You need to call the method off an object.

p = Prac()

Read this.

share|improve this answer
I tried calling the method from an interactive session, but got TypeError: 'module' object is not callable –  wbg Oct 2 '11 at 3:42
add comment

Your Answer


