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?

  • chicken@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    8
    ·
    9 days ago

    I usually put some print statements and stuff in the if block.

    The syntax is kind of weird and I have to regularly look it up, but it’s nice in a way because it makes it more obvious that this code isn’t going to run if you are importing the file rather than running it directly. Which implies a nice way to write something like a util.py, where there is no main function and what’s in the if block is for testing everything, not actually running the application.