r/learnpython • u/pedrinjose • 6d ago
Basically, if main
In Python, when you run your program in another folder, we add this, but I don't understand why. What's the point of doing this? If someone could explain it in a simplified way, I'd appreciate it.
10
Upvotes
View all comments
Show parent comment
1
u/Adrewmc 5d ago edited 5d ago
I mean https://github.com/python/cpython/blob/main/Lib/uuid.py
That what the command does…print to the shell, you lose it right after unless you copy it by hand…
That’s the example you used.
I merely asking for a use case that you really need to if __name__ == main? Printing to the shell isn’t a good example in my opinion as it basically ends there. I kind of see maybe it a bit easier if you run the same little things a lot, but in that case I would just make a specific entry file for that.
Writing a fast simple script is like what Python is known for.