Python: Novice Class object prac and __main__
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 "testi开发者_如何学运维ng function call"
if __name__ == ' __main__':
Fun()
That isn't a function, it's a method. You need to call the method off an object.
p = Prac()
p.Fun()
Read this.
精彩评论