Python Forum

Full Version: Program layout
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi was wanting to know is there a particular way of structuring a python program . For the last year and a half I've been using Basic and am trying to learn python . Been at it about a week and seem to be doing ok. However what I was wondering is how to structure a program like main with multiple subroutines or procedures . As I say I've only been at this a week so any good advice would be welcome .
Every program is different. A common pattern is to have a main() function from which everything starts, and then invoke it at the end of your script like this:
if __name__ == "__main__":
    main()
Global variables are considered bad, and object-oriented programming is often important to the proposed solution.

Beyond that, I think you'd get the most out of this question by asking about specific circumstances.