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.
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.
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.
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
).
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
All of mine are called do_thing()
because after a few days of working on it, the scope creep always means the original name was wrong anyway.
wait till you see
if __name__ = "__main__":
main()
`
Luckily Python is one step ahead:
Python 3.13.3 (main, Apr 22 2025, 00:00:00) [GCC 15.0.1 20250418 (Red Hat 15.0.1-0)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> if __name__ = "__main__":
...
... main()
...
File "<python-input-0>", line 1
if __name__ = "__main__":
^^^^^^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?
The if block is where my arg parser goes
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).
Nah self
is quite important. The main part of a method is to access the state of the object. self
is just the interface to it.
Guess I just prefer languages that do it this way:
class AClass {
var aProp = 0
fun aMethod() {
aProp++
}
}
Though I suppose confusion and bugs can happen when you do something like:
class AClass {
var aProp = 0
fun aMethod(aProp: Int) {
// `this.aProp` is needed to access the property
}
}