Thanks all my problem cleared.
Bhagwat

On Thu, Mar 20, 2008 at 11:02 PM, 7stud <[EMAIL PROTECTED]> wrote:

> On Mar 20, 10:21 am, "Simon Brunning" <[EMAIL PROTECTED]>
> wrote:
> > On Thu, Mar 20, 2008 at 4:12 PM, Bhagwat Kolde <[EMAIL PROTECTED]>
> wrote:
> > > Hi,
> > > I am new to the python and not getting meaning of following line,
> >
> > > if __name__ == '__main__':
> > >       main()
> >
>
> The if statement is used to skip the code after the if statement in
> certain situations.  If that if statement is in a file named test1.py,
> and you issue this command:
>
> $ python test1.py
>
> then the code after the if statement will execute.  That's because
> python assigns the string '__main__' to the variable __name__ when the
> program starts
>
> However, if you do this:
>
> -------
> #test1.py
> def my_func(num):
>    print num * 2
>
>
> if __name__ == "__main__":
>    print "Testing my func:", my_func(10)
>
> --------
>
> #test2.py
> import test1
>
> test1.my_func(5)
>
> -------
>
> ...and you issue the command:
>
> $python test2.py
>
> Then the code after the if statement in test1.py will not execute.
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Bhagwat K
"Play hard or go home"
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to