r/learnpython • u/pedrinjose • 5d 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.
9
Upvotes
View all comments
Show parent comment
1
u/Adrewmc 4d ago edited 4d ago
I’m pointing out that for the most part it’s sort of useless in the grand scheme of things to even use.
I just dont see much use of printing directly to shell and immediately losing the value as too important to programming.
I think you should be aware of the idea, but it really doesn’t have much use case for most programmers, especially people just learning.
However, knowing that things execute when call during the importing process is an importing thing to know.
Frankly I think they should just make built in function.
if is_root():
. #or a better keyword on the spot here
. main()