Also, do y’all call main() in the if block or do you just put the code you want to run in the if block?

  • bastion@feddit.nl
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    27 days ago

    All code needs to have an entry point.

    For Python and some other languages, this is the start of the file.

    For other languages, this is a special function name reserved for this purpose - generally, “main”.

    In the first kind of language, the thought process is basically: I have the flow of execution, starting at the top of the file. If I want to make a library, I should build the things I want to build, then get out of the way.

    In the other kind of language, the thought process is basically: I am building a library. If I want to make an executable, I should create an entry point they the execution starts at.

    The debate is honestly pretty dumb.

    • _stranger_@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      27 days ago

      Python doesn’t need the name main check to function at all. that’s just a convenience feature that lets developers also include arbitrary entry points into modules that are part of a library and expected to be used as such. If you’re writing a script, a file with a single line in it reading print("hello world") will work fine when run: python thescript.py