724

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?

(page 2) 50 comments
sorted by: hot top controversial new old
[-] driving_crooner@lemmy.eco.br 6 points 5 days ago

Does everyone call the function of the script main? I never use main(), just call the function what the program is supposed to do, this program calculates the IBNR? The function is called calculate_IBNR(), then at the end of the script if name = 'main': calculate_IBNR(test_params) to test de script, then is imported into a tkinter script to be converter to an exe with pyinstaller

load more comments (1 replies)
[-] 10001110101@lemm.ee 3 points 4 days ago

I've always found needing to manually add a class instance parameter (i.e. self) to every object method really weird. And the constructors being named __init__. Not having multiple dispatch is kinda annoying too. Needing to use decorators for class methods, static methods, and abstract classes is also annoying. Now that I think about it, Python kinda sucks (even though it's the language I use the most, lol).

load more comments (2 replies)
[-] match@pawb.social 12 points 5 days ago
[-] qx128@lemmy.world 11 points 5 days ago

Nothing prevents you from putting a call to “main()” in the global scope

[-] Static_Rocket@lemmy.world 7 points 5 days ago

Just cross your fingers nobody attempts to import it...

load more comments (1 replies)
load more comments (4 replies)
[-] jjjalljs@ttrpg.network 8 points 5 days ago

Call the function from the if block.

Now your tests can more easily call it.

I think at my last job we did argument parsing in the if block, and passed stuff into the main function.

[-] lmmarsano@lemmynsfw.com 6 points 5 days ago* (last edited 5 days ago)

Alternative: put entry point code in file __main__.py & run the containing package (eg, some_package) as a top-level expression (eg, python -m some_package).

load more comments (1 replies)
load more comments
view more: ‹ prev next ›
this post was submitted on 28 May 2025
724 points (96.3% liked)

Programmer Humor

23609 readers
1335 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS