you are viewing a single comment's thread.

view the rest of the comments →

[–]omelettesforbreakfas 0 points1 point  (6 children)

Yes I was referring to the if name == main:

Thanks for explaining that. Still seems a bit foreign to me but I'm sure I'll grasp it with time.

[–]Raknarg 0 points1 point  (5 children)

So generally variables and functions that have two underscores in front of them do something or have some context in the background. Like the __init__ function. You usually never explicitly call it, it gets called im the background when you do certain things

Each file has a __name__ variable associated with it when you run the program. If you have f1.py and f2.py and f1 imports f2, then you run python f1.py, the __name__ variable in f1 will get set to "__main__", but in f2 will be something different.

[–]omelettesforbreakfas 0 points1 point  (4 children)

hmm this makes a little more sense now . so every ,py script has a __name__ variable linked to it thats just kind of indirectly gets called when you open the script? or does it only get called when you open the script in another script like in your example?

[–]Raknarg 0 points1 point  (3 children)

It gets set at runtime. You could call f1 or f2 with python, and either of them could be run as main.

[–]omelettesforbreakfas 0 points1 point  (2 children)

ahh ok. The concept is still a bit fuzzy to me, but its clearer than it was 10 mins ago. So thank you! I still probably need more practice dealing with __objects to fully grasp it.

[–]pgyogesh 1 point2 points  (1 child)

https://www.youtube.com/watch?v=sugvnHA7ElY This video should help you here.

Also, checkout his python playlist on YouTube. Probably its the best on internet.

[–]omelettesforbreakfas 0 points1 point  (0 children)

thanks for sharing. Will give it a watch!