question about the mainloop

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Mon Apr 21 04:26:49 EDT 2008


globalrev a écrit :
> in C?? java etc there is usually:
> 
> procedure 1
> procedure 2
> procedure 3
> 
> main {
> procedure 1
> procedure 2
> procedure 3
> }
> 
> i dont get the mainloop() in python. 

The 'main' function (resp. method) in C and Java has nothing to do with 
a "mainloop" - it's just the program entry point, IOW the function that 
will get called when the program is executed.

Python has no such thing, since all code at the top-level is executed 
when the script is passed to the python runtime.

The notion of "mainloop" (or event loop) is specific to event-driven 
programs, which, once everything is set up, enter in a loop, wait for 
events to come, and dispatch them to appropriate handlers. And FWIW, 
there's no loop in your above example - the main() function will call 
procedures 1, 2 and 3 sequentially then exit.

> i mean i have written some
> programs, for example a calculator using tkinterGUI.
> 
> if i have some functions i wanna call to run the program

You don't "call some functions" to "run the program" - you pass your 
script to the python runtime, and all top-level code will be executed 
sequentially.




More information about the Python-list mailing list