How to know the starting point

Francesco Guerrieri f.guerrieri at gmail.com
Wed Sep 19 05:23:31 EDT 2007


On 9/19/07, Raj kumar <k_r_a_j_kumar at yahoo.co.in> wrote:
> Hi,
> I need help regarding the starting point in python project,
> As we can find main() function in java class to know the starting class in
> java,
> what is the starting point in python project?
> How to find the starting point.
> Thank you
>

There is no such thing, you can start where you like: try to write a
simple .py file defining some functions and classes and then using
them. Then launch the app by python your_file.py, and it will just
work.

You will often find a test like

if __name__ == '__main__':
   do_something()

__name__ is the variable which contains the name of the module. If the
module is being run as

python your_module.py,

the __name__ becomes '__main__' and the condition of the if statement
is satisfied.
This is a common method to define a starting point for a python application.
Keep in mind that many python modules are intended to be imported by
other modules and not to be used as standalone applications, but
rather as libraries. As such, they don't have a starting point, and
the
if __name__ == '__main__':

test could be used for instance to start a test suite.


francesco



More information about the Python-list mailing list