[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: newbie question
From:       "Chris Rebert" <clp () rebertia ! com>
Date:       2008-11-26 19:24:50
Message-ID: 47c890dc0811261124p4aa4fd63w5f89055d691e987f () mail ! gmail ! com
[Download RAW message or body]

On Wed, Nov 26, 2008 at 11:11 AM, Nan <nan.li.g@gmail.com> 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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic