725
submitted 1 week ago by [email protected] to c/[email protected]

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?

you are viewing a single comment's thread
view the rest of the comments
[-] [email protected] 20 points 1 week ago

Could someone explain this please? I'm still a noob.

[-] [email protected] 101 points 1 week ago

Python has a bunch of magic variables, like __name__. This one contains the name of the module you're currently in (usually based on the file name), so if your file is called foo.py, it will have the value foo.

But that's only if your module is being imported by another module. If it's executed directly (e.g. python foo.py), it will instead have a __name__ of __main__. This is often used to add a standalone CLI section to modules - e.g. the module usually only defines functions that can be imported, but when executed it runs an example of those functions.

[-] [email protected] 72 points 1 week ago

checks username

So it's you they're always talking about

[-] [email protected] 6 points 1 week ago

It is, it's the other Barry.

load more comments (1 replies)
load more comments (7 replies)
this post was submitted on 28 May 2025
725 points (96.3% liked)

Programmer Humor

23711 readers
2158 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