r/learnpython • u/pedrinjose • 10d 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.
11
Upvotes
View all comments
13
u/This_Growth2898 10d ago
Because you can import your file as a library and in that case you don't want it to run, just to import some functions.
ensures the file is called directly, not imported.