using cmd or powershell, calling python file returns no output
I've just installed python 2.7.2 on this machine. I'm attempting to run this code:
class Hello(object):
def main(self):
print "hello world"
if __name__ == "main":
h = Hello()
h.main()
When I call it with python ./foo.py, it does not return either a print 开发者_如何学JAVAstatement or log statement, just what appears to be a newline.
When I call it from a python shell it works as expected.
Additionally, I could write the file:
print "hello world"
And that will print in either powershell or cmd. What am I missing?
It's if __name__ == "__main__":
. You forgot the underscores around main
.
精彩评论