Beginner Question

Benjamin Kaplan benjamin.kaplan at case.edu
Mon Jan 19 21:32:45 CET 2009


On Mon, Jan 19, 2009 at 2:39 PM, K-Dawg <kdawg44 at gmail.com> wrote:

> Please forgive my beginner question.  I have used python a little bit,
> mainly as a scripting language to perform specific administrative tasks.  I
> have trying to learn to use it to develop applications but there are a few
> things I do not understand.
>
> I come from more of a Java background.
>
> I do no understand the underscore methods.  __main__  - is this just the
> main method that is in the file that is actually executed?  I also see
> __init__ a lot.  What is that for?  Is it like a constructor in Java or
> totally different?]


Python doesn't have a main method. It's files are scripts and not programs.
It's just like a shell script- everything is run. Unlike Java where
everything has to be in a method in a class, you can have actions performed
at the module level in Python. What you'll find is a lot of "if __name__ ==
'__main__'" conditionals. The name of the script that is run is always
__main__, so you can use this to only run certain commands when the script
is run directly as opposed to be imported by another module.

__init__ is the equivalent of a Java constructor.

>
>
> Thanks for clearing it up.  I am undertaking my first application
> development effort in python and anticipate discussing this with all of you
> a lot.  :)  Thanks for your support.
>
> Kevin
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090119/fe035d2c/attachment.html>


More information about the Python-list mailing list