On Wed, Nov 26, 2008 at 11:11 AM, Nan <[EMAIL PROTECTED]> wrote: > Hello, > I just started to use Python. I wrote the following code and > expected 'main' would be called. > > def main(): > print "hello" > > main > > But I was wrong. I have to use 'main()' to invoke main. The python > interpreter does not give any warnings for the above code. Is there > any way/tool to easily detect this kind of errors ?
Python has first-class functions, so you can pass a function to another function (so the line `main` has a meaning, just not a useful one). Also, Python doesn't do compile-time typechecking, so it has no way of knowing that `main` is a function and not a plain variable until runtime. Thus, the parentheses are required for a function call even when there are no arguments. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com > > Thanks ! > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list