Python Forum
I don't get the order of how things are executed with main()
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't get the order of how things are executed with main()
#2
def main(): # this is first, it is defined but doesn't do anything until called
    print("This is main") # this is eight
 
 
class user_input(): # this is second, it is defined but doesn't do anything until called
    print("This is class") this is fourth
 
print(user_input()) # this is third and fifth and actions straight away as its a statement and a function call in the global space
 
 
if __name__ == "__main__": # this is sixth and actions straight away as its a conditional statement in the global space
    main() # this is seventh and actions straight away as its a function call in the global space

The above is actually wrong, the print("This is class") happens when the class is defined so is actually third
You can use this link to visualise code execution
Reply


Messages In This Thread
RE: I don't get the order of how things are executed with main() - by Yoriz - Jul-20-2020, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to not open the context menu if a mouse gesture is executed? MicheliBarcello 2 763 Aug-22-2023, 02:47 PM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,812 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  code not working when executed from flask app ThomasDC 1 1,118 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  Can a variable equal 2 things? Extra 4 1,651 Jan-18-2022, 09:21 PM
Last Post: Extra
  Unusual things to do with unittest/HTMLTestRunner AndyHolyer 0 2,222 Jul-29-2020, 02:43 PM
Last Post: AndyHolyer
  Script works when executed from command prompt but not when executed in SDP Tippex 0 2,170 Apr-07-2020, 04:26 PM
Last Post: Tippex
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,232 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  Can a module be executed even if the computer running it does not install it? CFYB 5 3,570 Feb-08-2020, 01:56 PM
Last Post: snippsat
  C API: Writing Executed Code to a File myanrueller 0 1,791 Nov-17-2019, 09:35 PM
Last Post: myanrueller
  Urls in a file to be executed pyseeker 2 2,168 Sep-09-2019, 03:38 PM
Last Post: pyseeker

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020