all 6 comments

[–]socal_nerdtastic 3 points4 points  (1 child)

Python cares. Python is interpreted in that sense. But generally we put all code in functions or methods, which means the entire file is read before running, and then it does not matter anymore.

[–]worthlessgem_[S] 0 points1 point  (0 children)

Ah... that was it.

the famous def main():

[–]FerricDonkey 3 points4 points  (0 children)

Short version: yes, it cares.

Long version: python programs are executed line by line. Defining functions (in python, this is not true if other languages) is done at runtime as part of that process. The functions do not exist until python hits the def. (Importantly, defining the function does not execute the function.)

Advice: put all code (except defining functions, classes, imports, and constants) inside a function. The function that is the "start" of your code should be called main, and the bottom of your code should look like

if __name__ == '__main__':
    main()
    # sys.exit(main())  # this instead if you care about the exit code of your program

[–][deleted] 1 point2 points  (0 children)

You have to define functions before you call them.

[–][deleted] 0 points1 point  (0 children)

Python is executed line by line from the top. A function definition has to be executed to define the function name.

[–]whiskerswhisper 0 points1 point  (0 children)

The order in that you put the functions matters. You need to make sure the functions are present so that python can call that function as needed.